Set and unset default app in Android
Asked Answered
C

1

6

I have an application which I am attempting to "enter Kiosk mode" with, however I only want it to occur on only one Activity. After tinkering around with some of the controls, I came up with Intent.createChooser().

What I am trying to do is once the Activity's onCreate() is called, trigger Intent.createChooser() to prompt the user to set it as the default Home app; that way, I "disable" the Home button because I have programmed my launch Activity to lead straight back to my Kiosk Activity in this scenario.

Once the Kiosk Activity exits to the previous via a passcode, I want to call createChooser() again so that the user can "unset" my app as the default Home application, and he can now proceed with using the Home button as per normal.

The problem is, when I call createChooser(), the "Set as Default app" checkbox isn't appearing. How do I make it appear?

This is my code for calling createChooser():

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(Intent.createChooser(intent, "Set as default to enable Kiosk Mode"));

I've seen posts saying I should use startActivityForResult(), and I have tried replacing my startActivity() with the following:

startActivityForResult(intent, 1);

But this has simply called my default application immediately without the chooser screen popping up.

Casket answered 9/7, 2013 at 5:34 Comment(0)
B
4

Did you try

getPackageManager().clearPackagePreferredActivities(getPackageName());

According to How to reset default launcher/home screen replacement? this resets the preferred launcher. Maybe it also works for the home button.

Alternatively, did you have a look at: Clearing and setting the default home application?

Bedight answered 9/7, 2013 at 7:37 Comment(1)
Thanks Jack! The first link was exactly what I needed, it provided a very neat workaround to reset the default launcher app.Casket

© 2022 - 2024 — McMap. All rights reserved.