Skip to content

Instantly share code, notes, and snippets.

@Ayush783
Created January 7, 2025 06:18
Show Gist options
  • Save Ayush783/83ce7b7accd9c2454d25765a0b591d0c to your computer and use it in GitHub Desktop.
Save Ayush783/83ce7b7accd9c2454d25765a0b591d0c to your computer and use it in GitHub Desktop.
App links MainActivity class
package aayushsharma.me.app
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
class MainActivity: FlutterActivity() {
private lateinit var applinksMethodChannel: MethodChannel
companion object {
private const val APP_LINKS_CHANNEL_NAME = "MYAPP_APPLINKS_METHODCHANNEL"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
try {
val uri = intent.data
val data = if (uri?.host == "your_domain.com") uri.toString() else ""
applinksMethodChannel.invokeMethod("onAppLinkOpened", data)
} catch (e: Exception) {
Log.d("MainActivity", e.toString())
}
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
try {
val uri = intent.data
if(uri?.host == "your_domain.com") {
applinksMethodChannel.invokeMethod("onAppLinkOpened", uri.toString())
}
} catch (e: Exception) {
Log.d("MainActivity", e.toString())
}
}
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
applinksMethodChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, APP_LINKS_CHANNEL_NAME)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment