How to get the list of all non system apps in android

老子叫甜甜 提交于 2019-12-05 18:07:09

If an Application is a non-system application it must have a launch Intent by which it can be launched. If the launch intent is null then its a system App.

Example of System Apps: "com.android.browser.provider", "com.google.android.voicesearch".

For the above apps you will get NULL when you query for launch Intent.

PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for(ApplicationInfo packageInfo:packages){
    if( pm.getLaunchIntentForPackage(packageInfo.packageName) != null ){
                String currAppName = pm.getApplicationLabel(packageInfo).toString();
               //This app is a non-system app
    }
    else{
        //System App
    }
}

Criteria of having launch intent only, may not be reliable. it lists some system apps as non-system apps and vice versa. following code gives all the non-system apps which are launchable, and it works perfectly fine.

    PackageManager pm = getPackageManager();
    List<ApplicationInfo> packages = m.getInstalledApplications(PackageManager.GET_META_DATA);
    for(ApplicationInfo appInfo:packages)
    {
        String currAppName = pm.getApplicationLabel(appInfo).toString();
        String srcDir = appInfo.sourceDir;
        //Log.d(TAG, currAppName+": "+srcDir);
        if(srcDir.startsWith("/data/app/") && pm.getLaunchIntentForPackage(appInfo.packageName) != null)
        {
            Log.d(TAG, "NON-SYSTEM APP:"+srcDir);
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!