How to implement a launcher chooser dialog in a Flutter app for Android?

114 Views Asked by At

I am currently developing an Android launcher app using Flutter, and I'm working on implementing a feature where, upon pressing the home button, the user is prompted to choose between the default launcher and my custom launcher app, with options for "Just Once" or "Always."

I followed the instructions on this site, adding the following code to the AndroidManifest.xml:

<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
    <category android:name="android.intent.category.HOME"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

However, this didn't yield the expected behavior. Additionally, I attempted to use the "intent" package in Dart, but it seems to be incompatible with Dart 3. The code snippet I used is as follows:

void displayDefaultLauncherChooser() {
  intentFlutter
    .Intent()
      ..setAction(actionFlutter.Action.ACTION_MAIN)
      ..addCategory("android.intent.category.HOME")
      ..addCategory("android.intent.category.DEFAULT")
      ..addFlag(flag.Flag.FLAG_ACTIVITY_NEW_DOCUMENT)
      ..startActivity()
      .catchError((e) => print("intent error: " + e.toString()));
}

I came across a similar issue on Stack Overflow here, where I obtained the above code. Unfortunately, the provided solution didn't work for me. Notably, after updating to a new version, the intentFlutter function mentioned in the provided code is no longer available. The new intent package released is android_intent_plus, but I couldn't find an equivalent function.

Can anyone clarify where this function is moved or suggest an alternative approach to achieving the launcher chooser dialog in Flutter for Android using the android_intent_plus package? Your insights and guidance on the correct implementation would be highly appreciated. Thank you!

0

There are 0 best solutions below