Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, lets describe order of actions to obtain the label:</p> <ol> <li>Obtain <code>ApplicationInfo</code> (application info has <a href="http://developer.android.com/reference/android/content/pm/PackageItemInfo.html#labelRes" rel="noreferrer"><code>public int labelRes</code></a> - resource id of the label);</li> <li>Obtain application resources to retrieve <code>labelRes</code> from it - using <a href="http://developer.android.com/reference/android/content/pm/PackageManager.html#getResourcesForApplication%28java.lang.String%29" rel="noreferrer">getResourcesForApplication()</a>;</li> <li>Set necessary locale to obtained <code>Resources</code> and retrieve string <code>labelRes</code> (please note, that I haven't mentioned <a href="http://developer.android.com/reference/android/content/pm/PackageItemInfo.html#nonLocalizedLabel" rel="noreferrer">nonLocalizedLabel</a> which should be checked before doing all above items);</li> </ol> <p>The code itself is pretty simple (e.g. code from activity class):</p> <pre><code> PackageManager pm = getPackageManager(); try { ApplicationInfo galleryInfo = pm.getApplicationInfo("com.android.gallery3d", PackageManager.GET_META_DATA); if (null != galleryInfo) { final String label = String.valueOf(pm.getApplicationLabel(galleryInfo)); Log.w(TAG, "Current app label is " + label); final Configuration config = new Configuration(); config.locale = new Locale("ru"); final Resources galleryRes = pm.getResourcesForApplication("com.android.gallery3d"); galleryRes.updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); final String localizedLabel = galleryRes.getString(galleryInfo.labelRes); Log.w(TAG, "Localized app label is " + localizedLabel); } } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Failed to obtain app info!"); } </code></pre> <p>Produces the following output (second string label is in Russian locale which I set from code - 'ru'):</p> <pre><code>08-16 19:23:04.425: WARN/MyActivity(29122): Current app label is Gallery 08-16 19:23:04.425: WARN/MyActivity(29122): Localized app label is Галерея </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload