简体   繁体   中英

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 , ie 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.

For now I found the following solution and it works

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM