DanielJ
DanielJ

Reputation: 769

How to open Default Home App screen intent on Android

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?

Default Home App Chooser

Upvotes: 0

Views: 3009

Answers (1)

Amirhosein
Amirhosein

Reputation: 4446

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>

Upvotes: 1

Related Questions