List of default apps showing wrong in Android L
Asked Answered
Q

2

11

I want to get all default apps in Android L. I used bellow code but they give me a wrong solution. Let see my code first

private void getMyAppLauncherDefault() {
    final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);
    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    filters.add(filter);
    List<ComponentName> activities = new ArrayList<ComponentName>();
    final PackageManager packageManager = (PackageManager) getPackageManager();

    packageManager.getPreferredActivities(filters, activities, null);
    for (ComponentName activity : activities) {

        Log.d(TAG,"======packet default:==="+activity.getPackageName());
    }
}

And this is log. The log shows a wrong result between com.google.android.googlequicksearchbox and com.vlingo.midas. They are both Voice apps, but I set up com.google.android.googlequicksearchbox as default. I do not know why the log shows com.vlingo.midas. How can I fix it? Thanks

 16:02:44.817 /com.exam D/Sample: ======packet default:===com.sec.android.gallery3d
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.android.mms
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.android.mms
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.vlingo.midas
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.sec.android.app.sbrowser
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.sec.android.gallery3d
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.android.mms
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.sec.android.app.launcher
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.sec.android.app.sbrowser
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.android.mms
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.google.android.googlequicksearchbox
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.sec.android.app.sbrowser
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.sec.android.gallery3d
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.android.mms
 16:02:44.827 /com.exam D/Sample: ======packet default:===com.google.android.apps.plus

update: There are default app names enter image description here

Quatrefoil answered 9/11, 2016 at 7:13 Comment(3)
It is likely that com.vlingo.midas supports an additional filter, for which it shows up. Print the respective filter with the package name to check for this.Wyler
@F43nd1r: How can we print it? The filter size just 1, while filters size is 4. But I cannot print the name of filtersQuatrefoil
may be com.vlingo.midas is default for different purpose/application.Apis
H
2

To check if your App is set as "Default" then please try this code:

 public static boolean isMyAppDefault(Context context) {
        final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
        filter.addCategory(Intent.CATEGORY_HOME);

        List<IntentFilter> filters = new ArrayList<IntentFilter>();
        filters.add(filter);

        final String myPackageName = context.getPackageName();
        List<ComponentName> activities = new ArrayList<ComponentName>();
        final PackageManager packageManager = (PackageManager) context.getPackageManager();

        packageManager.getPreferredActivities(filters, activities, null);

        for (ComponentName activity : activities) {
            if (myPackageName.equals(activity.getPackageName())) {
                return true;
            }
        }
        return false;
    }
Hearty answered 17/11, 2016 at 9:31 Comment(2)
@user8430 if you get any problem let me know.Hearty
I think you and me get same source from someone. In your solution, it is similar my code above, just modify something. Please check your solution before posting.Quatrefoil
E
2

The code you added above is perfectly right. It does perform what it is meant to.

Now you have set com.google.android.googlequicksearchbox voice app as default and that's why it's showing up in the log. While com.vlingo.midas is showing probably because it's set as default for some other kind of category instead of voice.

Enrichment answered 17/11, 2016 at 9:59 Comment(4)
How can you prove it? I do not think so. I check allQuatrefoil
@user8430 I will need to try it out to prove it. I'll try it out and let you knowEnrichment
Do you find the solution. I am still looking forward to your testingQuatrefoil
@user8430 I haven't tested yet. I'll surely try it as soon as possible.Enrichment

© 2022 - 2024 — McMap. All rights reserved.