The Android custom application instructions aren't compatible with the default files that Flutter generates
Does anyone know how to set up a custom application class like they describe in these instructions for intercom_flutter?
Setup custom application class if you don't have any. Create a custom android.app.Application class named MyApp.
import android.app.Application
import io.maido.intercom.IntercomFlutterPlugin
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
// Add this line with your keys
IntercomFlutterPlugin.initSdk(this, appId = "appId", androidApiKey = "androidApiKey")
}
}
Open your AndroidManifest.xml and find the application tag. In it, add an android:name attribute, and set the value to your class' name, prefixed by a dot (.).
<application android:name=".MyApp" >
My problem is that they instruct you to adjust the <application android:name="${applicationName}"> field in AndroidManifest.xml and, as you can see, I have flutter defining it as 'applicationName'. I'd prefer not to modify what seems like an important part of the AndroidManifest.xml config?
How do I know what the value of that is? And then I should name it in the class below? I'm not very experienced with the Android side!
I've also posted this question to Stackoverflow: https://stackoverflow.com/questions/78444806/how-to-set-up-a-custom-application-class-with-flutters-configuration
No problem with overwriting <application android:name="${applicationName}">.
To include specific initializations for Flutter that Application does not include, do it as follows:
import io.flutter.app.FlutterApplication
import io.maido.intercom.IntercomFlutterPlugin
class MyApp : FlutterApplication() {
override fun onCreate() {
super.onCreate()
IntercomFlutterPlugin.initSdk(this, appId = "appId", androidApiKey = "androidApiKey")
}
}
Another thing, don't forget to pass the package name in the file type package br.com.myapp
package br.com.myapp
import io.flutter.app.FlutterApplication
import io.maido.intercom.IntercomFlutterPlugin
class MyApp : FlutterApplication() {
override fun onCreate() {
super.onCreate()
IntercomFlutterPlugin.initSdk(this, appId = "appId", androidApiKey = "androidApiKey")
}
}
@Nitrodist Did you manage to setup the custom application class?
@Nitrodist There is no issue in modifying the AndroidManifest file. You can check the example app for more clarification.