how to add a permission in APK ?

746 views
Skip to first unread message

Nino Porcino

unread,
Jan 21, 2018, 5:26:27 AM1/21/18
to DroidScript
the docs say it's possible to remove a permission from the APK via build.json file, but what about adding one?

Specifically I would like to add the "REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" in order for by background service to not be dozed by the O.S.

I tried "addPermissions", but it doesn't seem to work.

Is there a way/workaround? 

Steve Garman

unread,
Jan 21, 2018, 6:40:50 AM1/21/18
to DroidScript
_AddPermissions() only allows you to add permissions to your apk if those permissions are available in the DroidScript manifest. You can search for more information on that in this group.

With regard to the specific permission you refer to, this is not available in any of the _AddPermisdions groups.

In a previous thread, Dave suggested you look at
https://stackoverflow.com/questions/33114063/how-do-i-properly-fire-action-request-ignore-battery-optimizations-intent

If comments in that thread are correct, you do not need that permission and indeed Google Play will remove your app if you try to request it.

The suggested workaround is to talk the user through adding your app to the list of apps that are allowed to ignore the settings.

You can send them to the relevant Settings page using the following code:
var action = 'android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS'
app.SendIntent(null, null, action);

Nino Porcino

unread,
Jan 21, 2018, 6:58:31 AM1/21/18
to DroidScript
Steve, thanks for the precious info, I tried before to send the intent you mentioned but with the wrong arguments, so it was not working :-)

Now at least I can show the page for whitelisting the app, thanks!

I also wonder if there is a way to determine if the app is already whitelisted, an equivalent of what they can do in Java:


Is there a sort of "PowerManager" object in DroidScript? (I guess if not could it be created via a Plugin?)

Regarding the permission in the manifest, my last option would be to deassemble the APK, add the permission in the manifest, and reassemble it again, but that would involve signing the app with a different key. Too much trouble for a novice like me.

Reply all
Reply to author
Forward
0 new messages