Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set and unset default app in Android

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.

like image 766
Wakka02 Avatar asked Oct 04 '22 14:10

Wakka02


1 Answers

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?

like image 116
Jack Miller Avatar answered Oct 17 '22 13:10

Jack Miller