Saturday, June 8, 2019

Way to call Default Launcher by Custom Launcher

It would not be guaranteed to work always properly, though it works well in my case

1. manifest example

<activity ... android:label="@string/app_name" android:name=".activities.LauncherActivity" android:theme="@style/FullscreenTheme">
 <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>

2. custom launcher code example

var launcher_list = packageManager.queryIntentActivities(Intent(Intent.ACTION_MAIN).apply { addCategory(Intent.CATEGORY_HOME) },0)
val name = ComponentName(
 //expecting first element of launchers be the default
 launcher_list[0].activityInfo.packageName,
 launcher_list[0].activityInfo.name
)

val i = Intent(Intent.ACTION_MAIN)
i.addCategory(Intent.CATEGORY_LAUNCHER)
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
i.setComponent(name)

startActivity(i)
finish()

No comments:

Post a Comment

[osx command] file or folder monitoring

1. command fswatch [file or folder to monitor] | xargs -I {} echo $(date) {} >> [log file name] ...