How can I listen to which app has been chosen as Launcher Application? How can I listen to which app has been chosen as Launcher Application? android android

How can I listen to which app has been chosen as Launcher Application?


Try using the following code:

PackageManager localPackageManager = getPackageManager();Intent intent = new Intent("android.intent.action.MAIN");intent.addCategory("android.intent.category.HOME");String launcherName = localPackageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;Log.e("Current launcher Package Name:",launcherName);


With getPreferredActivities() you can retrieve all activities which are preferred by the user. This should include the launcher as well.

Then you could try to implement a getPreferredLauncher() function to get the current Launcher. But since there's no way to listen for this change, you'd have to query it proactively within a Service or whenever you'd assume the data could have changed:

fun PackageManager.getPreferredLauncher(): ComponentName? {    val filters = mutableListOf<IntentFilter>()    val components = mutableListOf<ComponentName>()    getPreferredActivities(filters, components, null)    filters.forEachIndexed { (i, it) ->        if (it.hasAction(ACTION_MAIN) && it.hasCategory(CATEGORY_LAUNCHER))            return@getPreferredLauncher components[i]    }    return null}

Please consider this code a draft only, as I didn't have any setup to actually run it.