2

我的最终目标是让用户能够从我的应用程序中打开另一个应用程序(例如 Google chrome 等)。我的尝试是创建一个包含所有已安装应用程序及其包名称的数组,并使用 Intent 使用包名称打开第三方应用程序。

我不知道如何通过电话找到包裹名称。有人可以指导我正确的方向吗?

4

3 回答 3

1

使用PackageManager

PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) 
{
    Log.d(TAG, "Installed package :" + packageInfo.packageName);
    Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
}
于 2013-11-06T18:19:39.303 回答
1

如果您只想获取并显示下载的应用程序(而不是系统应用程序),那么只需使用此代码即可解决您的问题。

    List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
    for (int i = 0; i < packs.size(); i++) 
    {
        PackageInfo packageInfo = packs.get(i);
        ApplicationInfo applicationInfo = packageInfo.applicationInfo;
        // Skips the system application (packages)
        if ( applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
        {
            continue;
        }

        String name = packageInfo.packageName;
        String versionName = packageInfo.versionName;
        String versionCode = packageInfo.versionCode;
       }
于 2014-07-10T12:07:01.150 回答
0

use this intent to get list of apps installed

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);

or using [package manager][1] which I prefer

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

for (ApplicationInfo packageInfo : packages) {
    Log.d(TAG, "Installed package :" + packageInfo.packageName);
    Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
}
// the getLaunchIntentForPackage returns an intent that you can use with startActivity()

and to get package name use this

String packagename= MyApp.getContext().getPackageName();
于 2013-11-06T18:19:03.160 回答