0

In my new app I am going to start other apps from my own app. But finding packagenames to all the apps is quite hard. I manage to make an app that finds the package name on all my current installed apps, but it would be much easier with some sort of online database or knowing where to look at the market.

Are there any online packagename databases, or do I have to find them out all by myself using my "packagename app"?

4

1 回答 1

2

如果您要从其他应用程序获取信息,您可以使用下面的代码。代码可能包含一些小错误,但它会给你一个很好的起点。

class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
    Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}

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

private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();        
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
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; 
}

如果您需要访问系统应用程序,可以尝试使用以下代码:

((packs.get(i).applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) { continue; }

为什么要使用在线数据库来检索包名称。请告诉我您为什么要使用在线数据库,以便我可以向您发布更多信息。如果我们查看 android market url(google play),我们可以看到它在应用程序的 url 中包含包名称。例子:https://play.google.com/store/apps/details?id=com.speaker.app id= 是包名。这可以帮助您了解在哪里可以根据需要查看市场。

如果您真的需要一个在线数据库:我建议您使用某种 sql 并从您的应用程序中请求“信息”。这需要一些服务器后端编程知识。

于 2012-06-11T19:22:48.667 回答