如何从android中的google play商店获取已安装应用程序的列表? [英] How to get the list of installed application from google play store in android?

查看:68
本文介绍了如何从android中的google play商店获取已安装应用程序的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要从 google play 或任何外部存储安装的应用程序列表,而不是预安装的系统应用程序.

i want the application list that is installed from google play or from any external storage, but not the pre installed system application.

我只是使用下面的代码.....

i just use below code.....

 class PInfo {
    private String appname = "";
    private String pname = "";
    private String versionName = "";
    private int versionCode = 0;
    private Drawable icon;
    private void prettyPrint() {
        Log.v("", "*** appname = " + appname + " *** \n" + " packagename = " + pname + "\n" + " version name =  " + versionName + "\n" + " version code = " + versionCode + " \n\n\n\n");
    }
}

private ArrayList<PInfo> getPackages() {
    ArrayList<PInfo> apps = getInstalledApps(true); /* false = no system packages */
    final int max = apps.size();
    int i = 0; 
    for (i=0; i<max; i++) {
        apps.get(i).prettyPrint();
    }
    Log.v(TAG, "Total APPs = "+i);
    return apps;
}

private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
    ArrayList<PInfo> res = new ArrayList<PInfo>();        
    List<PackageInfo> packs = getPackageManager().getInstalledPackages(PackageManager.GET_META_DATA);
    for(int i=0;i<packs.size();i++) {
        PackageInfo p = packs.get(i);
        if ((!getSysPackages) && (p.versionName == null)) {
            continue ;
        }
        PInfo newInfo = new PInfo();
        newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
        newInfo.pname = p.packageName;
        newInfo.versionName = p.versionName;
        newInfo.versionCode = p.versionCode;
        newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
        res.add(newInfo);
    }
    return res; 
}

但是这段代码也给了我系统应用程序的信息......

but this code gives me information of system application also.....

谁能知道除了已安装的系统应用程序之外,如何只获取已安装的应用程序?

can anybody know how to get only installed application except the installed system application ?

谢谢....

推荐答案

要确定您的应用程序是否是系统应用程序,您可以使用以下代码:

To discover if your application is a system application you can use the following code:

PackageManager pm = getPackageManager();
List<ApplicationInfo> installedApps = pm.getInstalledApplications(0);

for (ApplicationInfo aInfo: installedApps) {

    if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
        // system application
    } else {
        //user application
    }
}

如果您需要发现应用程序是否是从市场安装的,您需要使用 以下包方法:getInstallerPackageName.它将返回安装您的应用程序的应用程序的 packageName.

If you need to discover if an application is installed from a market you need to use the following method of Package: getInstallerPackageName. It will return the packageName of the application that installed your application.

这篇关于如何从android中的google play商店获取已安装应用程序的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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