Starting from Android 11 I've been having troubles with requesting permissions on Pixel 3a Xl (after update to android11).
So I have this app gradle file:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion '30.0.2'
defaultConfig {
applicationId "nnt.codecexp"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.0'
implementation "com.google.android.gms:play-services-maps:17.0.0"
implementation "com.google.android.gms:play-services-location:17.0.0"
}
and the code of MainActivity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
}
@Override
protected void onStart() {
super.onStart();
String[] permissions = {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION
};
requestPermissions(permissions, 0);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
for (int i = 0; i < permissions.length; i++) {
String permission = permissions[i];
boolean isGranted = grantResults[i] >= 0;
Log.d("atf", permission+" isGranted: "+isGranted);
}
}
}
I do a fresh install of the app on my device from Android Studio and the logs show me that permissions where automatically denied without getting any prompt for granting permissions. (The prompt window is not shown). I understand that on android 11 if the user denies permissions like 2 times, the system will skip the prompt dialog on following permissions request and they will be automatically denied. But this is not the case, the issue happens right after a fresh install of the App. (the app is not present on the device when launched from Android Studio)
However: if I change in the gradle file "targetSdkVersion 30" to "targetSdkVersion 29" everything works properly, as expected.
Can anyone tell me why is this happening and is keeping "targetSdkVersion 29" a good solution for this problem?
Am I doing something wrong? or is that just Google [censored] [censored] [censored].