开发者

Get list of Non System Applications

开发者 https://www.devze.com 2023-01-08 16:10 出处:网络
I\'m able to get a list of installed packages using the package manager, but this includes various system packages . Are there any filters i can ap开发者_运维百科ply on this list to only show the apps

I'm able to get a list of installed packages using the package manager, but this includes various system packages . Are there any filters i can ap开发者_运维百科ply on this list to only show the apps that would show up when bringing up the application list from the home screen?


boolean nonSystem = (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0;


You can use intent filtering to get the application list from the home screen:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> apps = getPackageManager().queryIntentActivities(intent, 0);


THE ABOVE ANSWERS WILL NOT WORK IN ALL CASES

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 else its a non-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
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消