如何从谷歌Play商店Android中安装应用程序的列表?
我想,从谷歌Play或任何外部存储安装的应用程序列表中,但不是pre安装的系统应用。
i want the application list that is installed from google play or from any external storage, but not the pre installed system application.
我只是使用下面code .....
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;
}
但这种code给我系统的应用也......
but this code gives me information of system application also.....
能有人知道如何得到的只是安装的应用程序,除了已安装的系统应用?
can anybody know how to get only installed application except the installed system application ?
感谢....
要发现,如果你的应用程序,你可以使用下面的code系统应用程序:
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.