Reputation: 4958
Is it possible to detect what the default launcher app is on a device from within your app?
I am poking around with PackageManager but don't seem to see what i am looking for, i would like my app of launcher type to behave differently when set as the default launcher so i am trying to programmatically detect whether the use has set it to be the default launcher or not
the code i tried below returns Android System no matter what i set as the default launcher:
pm = getApplicationContext().getPackageManager();
Intent i = (new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER));
final ResolveInfo mInfo = pm.resolveActivity(i, 0);
Log.v("curent default launcher",":::::::::"+ pm.getApplicationLabel(mInfo.activityInfo.applicationInfo));
Upvotes: 1
Views: 1708
Reputation: 22306
In the example that Google provides for a launcher replacement the activity has the following definition in the manifest:
<activity android:name="Home"
android:theme="@style/Theme"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<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>
Based on that you should add the following categories for querying for the launcher
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
i.addCategory(Intent.CATEGORY_DEFAULT);
Upvotes: 2