How can I dynamically detect whether my application is system or normal?

前端 未结 5 2089
失恋的感觉
失恋的感觉 2021-02-14 11:53

How do I differentiate between a system app and a normal app ? I looked through android PackageManager and could not find any.

Edit: I want

5条回答
  •  离开以前
    2021-02-14 12:18

    You could try using the flags available in the ApplicationInfo class (android.conent.pm). For example:

    ...
    PackageManager pm = getPackageManager();
    List installedApps = pm.getInstalledApplications(0);
    
    for (ApplicationInfo ai: installedApps) {
    
        if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            // System app - do something here
            ...
        } else {
            // User installed app?
        }
    }
    

提交回复
热议问题