pubspec.yaml : add flushbar dependencie | lib : delete HomeLog.dart, add endi.dart (start only if deeplink is clicked), add bloc.dart (manage deeplink fonctionnality) | ios/Runner/info.plist : add endi URIs | android/app/src/main/AndroidManifest.xml : add endi URIs | android/app/src/main/kotlin/fr.astrolabe.astronote_app/MainActivity.kt : update to manage deeplink fonctionnality
This commit is contained in:
@@ -1,6 +1,69 @@
|
||||
package fr.astrolabe.astronote_app
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.os.Bundle
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.annotation.NonNull
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.EventChannel
|
||||
import io.flutter.plugin.common.EventChannel.EventSink
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
class MainActivity : FlutterActivity() {
|
||||
|
||||
private val CHANNEL = "https://demo.endi.coop"
|
||||
private val EVENTS = "https://demo.endi.coop/login?nextpage=%2F"
|
||||
private var startString: String? = null
|
||||
private var linksReceiver: BroadcastReceiver? = null
|
||||
|
||||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
||||
GeneratedPluginRegistrant.registerWith(flutterEngine)
|
||||
|
||||
MethodChannel(flutterEngine.dartExecutor, CHANNEL).setMethodCallHandler { call, result ->
|
||||
if (call.method == "initialLink") {
|
||||
if (startString != null) {
|
||||
result.success(startString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EventChannel(flutterEngine.dartExecutor, EVENTS).setStreamHandler(
|
||||
object : EventChannel.StreamHandler {
|
||||
override fun onListen(args: Any?, events: EventSink) {
|
||||
linksReceiver = createChangeReceiver(events)
|
||||
}
|
||||
|
||||
override fun onCancel(args: Any?) {
|
||||
linksReceiver = null
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val intent = getIntent()
|
||||
startString = intent.data?.toString()
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
if (intent.action === Intent.ACTION_VIEW) {
|
||||
linksReceiver?.onReceive(this.applicationContext, intent)
|
||||
}
|
||||
}
|
||||
|
||||
fun createChangeReceiver(events: EventSink): BroadcastReceiver? {
|
||||
return object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) { // assuming intent.getAction() is Intent.ACTION_VIEW
|
||||
val dataString = intent.dataString
|
||||
?: events.error("UNAVAILABLE", "Link unavailable", null)
|
||||
events.success(dataString)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user