diff --git a/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt b/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt
index 8ef7103..25dac9b 100644
--- a/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt
+++ b/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt
@@ -3,6 +3,7 @@ package com.amplitude.amplitude_flutter
import android.content.Context
import com.amplitude.api.Amplitude
import com.amplitude.api.Identify
+import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
@@ -11,18 +12,31 @@ import io.flutter.plugin.common.PluginRegistry.Registrar
import org.json.JSONArray
import org.json.JSONObject
-class AmplitudeFlutterPlugin : MethodCallHandler {
- companion object {
+class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler {
+ companion object {
+
+ private const val methodChannelName = "amplitude_flutter"
+
var ctxt: Context? = null
@JvmStatic
fun registerWith(registrar: Registrar) {
ctxt = registrar.context()
- val channel = MethodChannel(registrar.messenger(), "amplitude_flutter")
+ val channel = MethodChannel(registrar.messenger(), methodChannelName)
channel.setMethodCallHandler(AmplitudeFlutterPlugin())
}
}
+ override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
+ ctxt = binding.applicationContext
+ val channel = MethodChannel(binding.binaryMessenger, methodChannelName)
+ channel.setMethodCallHandler(AmplitudeFlutterPlugin())
+ }
+
+ override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
+
+ }
+
override fun onMethodCall(call: MethodCall, result: Result) {
val json = JSONObject(call.arguments.toString())
val instanceName = json["instanceName"].toString()
diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml
index c4bf723..6ae5595 100644
--- a/example/android/app/src/main/AndroidManifest.xml
+++ b/example/android/app/src/main/AndroidManifest.xml
@@ -10,6 +10,11 @@
android:name="io.flutter.app.FlutterApplication"
android:label="amplitude_flutter_example"
android:icon="@mipmap/ic_launcher">
+
+
+
-
+
+
+
+ android:name="io.flutter.embedding.android.SplashScreenDrawable"
+ android:resource="@drawable/launch_background" />
+
+
+
+
diff --git a/example/android/app/src/main/kotlin/com/example/amplitude_flutter_example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/amplitude_flutter_example/MainActivity.kt
index 993571a..b3f0d73 100644
--- a/example/android/app/src/main/kotlin/com/example/amplitude_flutter_example/MainActivity.kt
+++ b/example/android/app/src/main/kotlin/com/example/amplitude_flutter_example/MainActivity.kt
@@ -1,13 +1,8 @@
package com.example.amplitude_flutter_example
-import android.os.Bundle
-
-import io.flutter.app.FlutterActivity
-import io.flutter.plugins.GeneratedPluginRegistrant
+import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- GeneratedPluginRegistrant.registerWith(this)
- }
+ // You can keep this empty class or remove it. Plugins on the new embedding
+ // now automatically registers plugins.
}
diff --git a/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml
index 00fa441..992144e 100644
--- a/example/android/app/src/main/res/values/styles.xml
+++ b/example/android/app/src/main/res/values/styles.xml
@@ -5,4 +5,8 @@
Flutter draws its first frame -->
- @drawable/launch_background
+
+