简体   繁体   English

如何从Android中的google play商店获取已安装应用程序的列表?

[英]How to get the list of installed application from google play store in android?

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 ? 任何人都知道除了已安装的系统应用程序之外如何只安装应用程序?

thanks.... 谢谢....

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

If you need to discover if an application is installed from a market you need to use the following method of Package: getInstallerPackageName . 如果您需要发现是否从市场安装了应用程序,则需要使用以下 Package方法: getInstallerPackageName It will return the packageName of the application that installed your application. 它将返回安装了您的应用程序的应用程序的packageName。

public class AppList extends Activity {
 private ListView lView;
 private ArrayList results = new ArrayList();

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  lView = (ListView) findViewById(R.id.list1);
  PackageManager pm = this.getPackageManager();

  Intent intent = new Intent(Intent.ACTION_MAIN, null);
  intent.addCategory(Intent.CATEGORY_LAUNCHER);

  List list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
  for (ResolveInfo rInfo : list) {
   results.add(rInfo.activityInfo.applicationInfo
     .loadLabel(pm).toString());
   Log.w("Installed Applications", rInfo.activityInfo.applicationInfo
     .loadLabel(pm).toString());
  } 
  lView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在我的Android应用程序中获取谷歌游戏商店的信息? - how to get information of google play store in my android application? 如何直接从我的 Android 应用程序打开 Google Play 商店? - How to open the Google Play Store directly from my Android application? 如何从Google Play商店获取开发人员的应用程序排序列表 - How to get sorted list of apps, for a developer, from Google Play Store 确保从Play-Store安装Android应用程序 - Make sure the Android application was installed from Play-Store 如何从谷歌播放获取我自己的应用程序列表列表 - How to get list of my own application list from google play 如果安装了应用程序或导航用户从 Web 应用程序播放商店,如何打开 Android 应用程序 - How to open android app if app is installed or navigate user to play store from web application 获取从Google Play安装的应用程序的安装日期/时间 - Get installation date/time of an application installed from google play 创建可能不是从 Play 商店安装的应用程序 - Creating application that might be installed not from Play Store 如何在Android应用程序中获取Google Play引用程序 - How to get Google Play referer in an Android application 由于Google Play服务8.3.0,无法从Play商店安装Android应用 - Android app can not be installed from the play store because of Google Play Services 8.3.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM