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 .
Using android.R.string only returns a small portion of the strings.
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")
Is such a thing possible? If not, is it possible to do it with root?
Your link show how get resources from preferences screen and say :
The goal of this example was to show how to obtain the correct String resource outside the Android XML namespace
Link describe that you can get resources by alternative way ,not only by R.string.
I create a demo project with another custom namespace and custom button Label,but unfortunately i cannot show string resources from one project to another.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With