Sunny
Sunny

Reputation: 14808

How to filter system applications?

I want to filter system app only using their package name. How can I do this?

I know the below function filter the system app, but as I said above only using package name.

private boolean isSystemPackage(PackageInfo pkgInfo)
{
    return (pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
}

Upvotes: 0

Views: 243

Answers (2)

Jens-Joris Decorte
Jens-Joris Decorte

Reputation: 56

only using package name

You can filter out the system apps based on package names, but you will eventually always need the ApplicationInfo of the app.

You could use this method:

private boolean isSystemPackage(String packageName){
    PackageManager packageManager = MyActivity.this.getPackageManager();
    ApplicationInfo applicationInfo = null;
    try {
        applicationInfo = packageManager.getApplicationInfo(packageName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true
            : false;
}

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006539

How can i do this?

You don't. It is not possible. There is no package naming convention for "system apps".

Upvotes: 2

Related Questions