Home » Android » Get Associated Action For An App That Is Seeking Permission

Get Associated Action For An App That Is Seeking Permission

Posted by: admin November 1, 2017 Leave a comment


First, apologies if the question is worded incorrectly, I didn’t know how else to put it. So, what I am trying to do is to get an app name (like Camera in the below example), when a permission window (permission_warning_template) is triggered:

So, for English language the construct in the android ROM is thus:

<string name="permission_warning_template" msgid="7332275268559121742">"Allow &lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; to <xliff:g id="ACTION">%2$s</xliff:g>?"</string>

For example, for the Camera app, the red underlined is the id:"ACTION" :

enter image description here

It is fairly easy to get the APP_NAME from the English permission_warning_template as the APP_NAME is surrounded by 2 constants which are Allow and to and I parse the string returned, to get the word(s) between those 2 constant strings.

Problem begins, when we move to a different language like German etc. where the APP_NAME is immediately succeeded by id:"ACTION" as follows:

<string name="permission_warning_template" msgid="7332275268559121742">"Zulassen, dass die App &lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; <xliff:g id="ACTION">%2$s</xliff:g> darf?"</string>

and obviously, my string parsing logic doesn’t work (I cannot use a space as a delimiter for the parsing logic, as APP_NAME may have more than one word, like My Camera). Is there a way to know all possible/retrieve id:"ACTION" as a constant value so that I can retrieve the app name somehow?