对于手机上安装的所有应用程序,我需要访问:
名称
偶像
安装应用程序的google play url
我看过applicationinfo,但它似乎并没有向我提供这些信息。我听说过packageinfo和resolveinfo,但是我很困惑它们之间的区别是什么,应该在哪里使用哪一个?最后,我可以用什么来找到以上三个有关已安装应用程序的详细信息?
对于包名,我会得到com.something.some之类的东西
这是我用来获取应用程序的代码:

final PackageManager pm = getPackageManager();
ArrayList<ApplicationData> listAppData = new ArrayList<ApplicationData>();

//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo packageInfo : packages) {
    listAppData.add(new ApplicationData(packageInfo));
}

applicationdata是我自己的类,我从packageinfo中提取信息

最佳答案

此函数将返回包含图标、名称和程序包的应用程序列表。
使用该包,您可以使用以下内容构建URL:

https://play.google.com/store/apps/details?id= <PACKAGE>

见:
public class Application {

    private String packageName;
    private String name;
    private Drawable icon;
    private boolean checked;
...

private List<Application> getAllApplications(Context context)
            throws NameNotFoundException {

        PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> packages = packageManager.getInstalledPackages(0);

        List<Application> myPackages = new ArrayList<Application>();

        for (PackageInfo pack : packages) {
            if (pack.versionName == null) {
                continue;
            }

            Application newPack = new Application();
            newPack.setPackageName(pack.packageName);
            newPack.setName(pack.applicationInfo.loadLabel(packageManager)
                    .toString());
            newPack.setIcon(pack.applicationInfo.loadIcon(packageManager));

            myPackages.add(newPack);
        }

        return myPackages;
    }

关于android - ApplicationInfo与PackageInfo vs ResolveInfo,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20490022/

10-09 07:10