How to get a list of all non-system applications in android

I am developing an application in which I want to get a list of all non-system applications. Here is my piece of code:

TextView tv = new TextView(this); this.setContentView(tv); ActivityManager actvityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE ); PackageManager pm = this.getPackageManager(); List<PackageInfo> list =pm.getInstalledPackages(0); for(int i=0;i<list.size();i++) { System.out.println("list"+i+" "+list.get(i)); } for(PackageInfo pi : list) { try { ApplicationInfo ai=pm.getApplicationInfo(pi.packageName, 0); if (ai.sourceDir.startsWith("/data/app/")) { tv.setText(ai.className);// non system apps } else { System.out.println("system apps");// system apps } } catch(Exception e) { e.printStackTrace(); } } 

but it shows the whole application as system applications

+3
source share
2 answers

If the application is a non-system application, it must have an Intent running through which it can be launched. If the launch target is null, then this is a system application.

Example system applications: "com.android.browser.provider", "com.google.android.voicesearch".

In the above applications, you will get NULL when prompted to run 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 } } 
+12
source

Criteria for just starting a run can be unreliable. it lists some system applications as non-system applications and vice versa. The following code gives all non-system applications that start up and works 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); } } 
0
source

All Articles