获取未本地化的应用程序名称

3

我需要获取应用程序的名称,但不要带上本地语言,只需使用原始语言。 我来自波兰,我需要应用程序名称列表以原始英文显示! 我有以下代码:

final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
final List<ResolveInfo> activities = packageManager.queryIntentActivities( intent, 0 );
final int size = activities.size();
for (int i = 0; i < size; i++){
    final ResolveInfo info = activities.get(i);
    final String label = info.loadLabel(packageManager).toString();
    final String pkgName = info.activityInfo.packageName;
    final String className = info.activityInfo.name;
    Log.d("INFO", label);
}
1个回答

0
您可以使用包管理器中的getResourcesForApplication()。您可以设置资源文化并获取值。
请查看下面的代码:
PackageManager packageManager = getPackageManager();
final String packageName = "com.android.wallpaper.livepicker";
    try {
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);

        if (null != applicationInfo) {
            CharSequence label = packageManager.getApplicationLabel(applicationInfo);

            Log.d("MyTag", "Default app label is " + label);

            Configuration configuration = new Configuration();

            configuration.setLocale(new Locale("en"));

            Resources resources = packageManager.getResourcesForApplication(packageName);

            resources.updateConfiguration(configuration, getBaseContext().getResources().getDisplayMetrics());

            String localizedLabel = resources.getString(applicationInfo.labelRes);

            Log.d("MyTag", "Localized app label is " + localizedLabel);
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e("MyTag", "Failed to obtain app info!");
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接