Use this:
private boolean isMyLauncherDefault()
{
boolean returnValue = false;
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
intent.addCategory("android.intent.category.DEFAULT");
PackageManager pm = context.getPackageManager();
final ResolveInfo mInfo = pm.resolveActivity(intent, 0);
if (mInfo != null) {
if(myAppname.equals
(pm.getApplicationLabel(mInfo.activityInfo.applicationInfo))
returnValue = true;
}
return returnValue;
}
Edit:
getPreferredActivities:Returns the total number of registered preferred activities. Retrieve all preferred activities, previously added with addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName), that are currently registered with the system. I think this will return all the activities name which are registered for that particular intent.
resolveActivity:Returns a ResolveInfo containing the final activity intent that was determined to be the best action. Returns null if no matching activity was found. So in this case we have restricted resolve activity to match DEFAULT app by specifying CATEGORY_DEFAULT
.
Check this post answered by Hackborn that we should use resolveActivity()
to find default app.