I am building a custom launcher for a kid mode app. I have followed this link to create a launcher picker to let user choose my app as their default launcher.
The problem is if there is a default launcher in their devices, the code in the link above doesn't work. I am testing on Zenphone5, Android 4.4.2. I have seen some people have the same problem create launcher picker on Android 4.4.2.
I have searched everywhere on how to create a launcher picker like these: Nester, iWawa. How can they do that?
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ttb.com.kidmode">
<!-- Hide status bar -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<!-- Hide the recent apps -->
<uses-permission android:name="android.permission.REORDER_TASKS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light">
<activity android:name=".activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.KidModeActivity"
android:enabled="false">
<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>
</application>
Create launcher picker dialog:
if (isMyLauncherDefault() == false) { // enable fake home to force system to clear default
Log.v(">>>", "false");
ComponentName launcherActivity = new ComponentName(this, KidModeActivity.class);
getPackageManager().setComponentEnabledSetting(launcherActivity,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
goHome();
} else {
// Go home
goHome();
}
Pressing the Home button:
private void goHome() {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
}
EDIT
The full story is: "I open my app, and click a button to go to my launcher -> nothing happens (because another launcher is set as default). If I open that launcher setting (Setting -> Apps -> ..) and click "Clear Default", then open my app again, click button to go to my launcher -> The dialog will show up. From now, the code works well". I dont want to open setting to click "Clear Defalt"