Issue
I am developing a launcher app and want the user to get a pop up where they can choose my app as their default launcher, I have seen quite a few questions on stack overflow for the same, but they were for android. I am assuming that the only way to do this is with using intents so I tried using this intent package, I tried simulating the code here, android: choose default launcher programmatically, but wasn't able to successfully complete it. Is there a way to do it in Flutter? Anyway, here is my code from what I tried:
// method is called in initState()
void defaultLauncherOption() {
intentFlutter
.Intent()
..setAction("android.intent.action.MAIN")
..addCategory("android.intent.category.HOME")
..addCategory("android.intent.category.DEFAULT")
..addCategory("android.intent.category.LAUNCHER")
..startActivity().catchError((e) => print("intent error: " + e.toString()));
}
// the code doesn't give any errors but is not performing any operation as well.
Solution
in case anyone needs the answer to this question, I did it using the intent package and by the following code:
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()));
}
Answered By - Shlok Jain
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.