如何获取Android中所有非系统应用程序的列表 [英] How to get the list of all non system apps in android

查看:193
本文介绍了如何获取Android中所有非系统应用程序的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我想在其中获取所有非系统应用程序的列表.这是我的代码部分:

I am developing an application, in which i want to get the list of all non system apps. Here is my code part:

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 showing, all the app as system apps

推荐答案

如果应用程序是非系统应用程序,则它必须具有启动意图,通过它可以启动它.如果启动意图为空,则为系统应用程序.

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.

系统应用程序示例:"com.android.browser.provider","com.google.android.voicesearch".

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

对于上述应用,当您查询启动意图时,您将获得NULL.

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
    }
}

这篇关于如何获取Android中所有非系统应用程序的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆