2

I need to know the list of installed applications that can be launched by the user (for example: Browser, Email, Maps, etc.). I read this question about the getInstalledApplications method, so I wrote the following code:

final PackageManager pm = getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo app : apps) {
    Intent launchIntent = pm.getLaunchIntentForPackage(app.packageName);
if (launchIntent != null) {
        Log.d(LOG_TAG, "getApplicationLabel: " + pm.getApplicationLabel(app));
        Log.d(LOG_TAG, "loadLabel: " + app.loadLabel(pm));
        Log.d(LOG_TAG, "packageName: " + app.packageName);
        Log.d(LOG_TAG, "name: " + app.name);
    }
}

In this way I get the list of applications that can be launched. Each of these applications is characterized by a package name, so if I want to start one of these, just get the launch intent for the package by specifying the package name. This means that each package has at most an activity that can be launched, so each of the applications (which are returned by the getInstalledApplications method) should have a unique package name. Is that correct?

4

1 回答 1

2

Android 通常不会让您使用相同的包名称安装多个应用程序。根据我的经验,第二个应用程序的 .apk 文件不会安装,更不用说运行了。所以,不,每个包名你不会得到一个以上的应用程序。

但是,可以通过同一应用程序的意图启动多个活动。您的代码不会得到它们,因为 getLaunchIntentForPackage() 只返回一个意图,但每个活动都可以有自己的意图过滤器。http://developer.android.com/guide/topics/intents/intents-filters.html上的“记事本示例”具有三个不同的活动,每个活动都可以从外部启动。

于 2012-04-25T16:34:24.923 回答