Background
I would like to get all of the strings of the Android OS (including all of them) programmatically, including those that are considered private.
For example, I would like to get those of the packageManager app, as found here .
The problem
Using android.R.string only returns a small portion of the strings.
What I've tried
I've found this link, which shows the next code, but I'm not sure what to put into the parameters:
private String GetAttributeStringValue(Context context, AttributeSet attrs, String namespace, String name, String defaultValue)
{
//Get a reference to the Resources
Resources res = context.getResources();
//Obtain a String from the attribute
String stringValue = attrs.getAttributeValue(namespace, name);
//If the String is null
if(stringValue == null)
{
//set the return String to the default value, passed as a parameter
stringValue = defaultValue;
}
//The String isn't null, so check if it starts with '@' and contains '@string/'
else if( stringValue.length() > 1 &&
stringValue.charAt(0) == '@' &&
stringValue.contains("@string/") )
{
//Get the integer identifier to the String resource
final int id = res.getIdentifier(context.getPackageName() + ":" + stringValue.substring(1), null, null);
//Decode the string from the obtained resource ID
stringValue = res.getString(id);
}
//Return the string value
return stringValue;
}
I've seen some apps in the past that can list various resources of other apps, including of the system itself (example here).
Later I've found how to get a string from any app you wish, but it assumes you know the name of the identifier, and doesn't offer you to list them:
fun getStringFromApp(context: Context, packageName: String, resourceIdStr: String, vararg formatArgs: Any): String? {
try {
val resources = context.packageManager.getResourcesForApplication(packageName)
val stringResId = resources.getIdentifier(resourceIdStr, "string", packageName)
if (stringResId == 0)
return null
return resources.getString(stringResId, *formatArgs)
} catch (e: Exception) {
return null
}
}
For example, if you want to get the string of "more" (key is "more_item_label"), you can use :
val moreString = getStringFromApp(this,"android", "more_item_label")
The question
Is such a thing possible? If not, is it possible to do it with root?