Search code examples
androiddebugginggeolocationandroid-permissions

How to grant permissions to debugged android application?


I have

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

in my manifest but despite this my code tracing says that condition

 if (ActivityCompat.checkSelfPermission(this,
                android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                ActivityCompat.checkSelfPermission(this,
                        android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

is true, i.e. both permissions are not granted.

How to grant them then?

UPDATE

The logic of my application assumes not to REQUEST permissions. If they are granted, then it will work one way and if they are not granted, it will silently work without them.

So, I need to grant them as if application was installed and permissions were granted during installation.

UPDATE 2

I suspect the answer is somewhere in Run/Debug configurations of Android Studio.

For example, I see the following line in console while debugging

adb shell pm install -r "MYPATH"

and also I see here https://developer.android.com/studio/command-line/adb.html#pm that there is an option of -g saying to "Grant all permissions listed in the app manifest".

This is what I need to happen automatically.


Solution

  • For now I found the following solution and it works

    enter image description here