So, I want to get a string resource from another application. The application is an Android PackageInstaller (most likely a System application), and the line I want to get has several language versions (source code here> Link ). Thus, the Package Installer's resource directory is as follows:

I want to get String permission_warning_template from the values folder (I understand that Android will automatically detect the current language and bring me that language value, but I could be wrong).
These are two methods that I wrote (a minimal, complete and tested example), and none of them work. Is it possible? How to do it?
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //First Try testUseAndroidString(); //Second Try Resources res = null; try { res = getPackageManager().getResourcesForApplication("com.android.packageinstaller"); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } if(null != res) { int sId = res.getIdentifier("com.android.packageinstaller:string/permission_warning_template", null, null); if(0 != sId) { Log.d("TagLet", res.getString(sId)); } } } public void testUseAndroidString() { Context context = this; Resources res; try { res = context.getPackageManager().getResourcesForApplication("com.android.packageinstaller"); int resourceId = res.getIdentifier("com.android.packageinstaller:string/permission_warning_template", null, null); if(0 != resourceId) { CharSequence s = context.getPackageManager().getText("com.android.packageinstaller:string/permission_warning_template", resourceId, null); Log.d("TagLet", "resource=" + s); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } Log.d("TagLet", "FAIL"); } }
Thanks.
source share