2012-11-02 28 views
1

我想要从谷歌播放或从任何外部存储安装的应用程序列表,但不是预安装的系统应用程序。如何从Android的谷歌播放商店获得已安装的应用程序的列表?

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

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

但是这个代码给了我系统的应用也是一个信息.....

能有人知道如何获得除外仅安装的应用程序安装的系统应用程序?

感谢....

回答

3

发现,如果你的应用,你可以使用下面的代码的系统应用程序:如果您需要去发现如果一个应用程序从安装

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

一个市场你需要使用following方法包装:getInstallerPackageName。它将返回安装应用程序的应用程序的packageName。

0
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)); 
    } 
} 
+0

获取错误“无法从元素类型对象转换为”ResolveInfo“在线”for(ResolveInfo rInfo:list)“..... – Jayesh

相关问题