I'm developing an app to use as a home launcher. I understand that I am unable to programmatically clear the current home app launcher, but I wish to guide the user into choosing my app.
I understand how to check if my app is set as a home launcher by using the PackageManager
, however this does not give me a way to set the home App.
I also have tried to use an Intent
to select a home launcher, however this dialog which opens does not provide the user a mean to choose a default home launcher
final Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startActivity(Intent.createChooser(startMain, "Choose Home App));
However looking at a Launcher (Nova) I can see it seems to run an intent to open a native launcher screen. How do I do this?
PackageManager packageManager = activity.getPackageManager();
ComponentName componentName = new ComponentName(activity, YourLauncher.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
activity.startActivity(intent);
activity.finishAndRemoveTask();
and launcher activity in the manifest:
<activity
...
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>