I'm developing an app on two different computers, and using github to sync the project using Android Studios git tools. I can't get the permissions right after I ran my app from my secondary workstation.
It seems ActivityCompat.checkSelfPermission() returns true even if the app doesn't have the required permissions, which leads the app to skip the ActivityCompat.requestPermissions() method.
Android Studio asks me to reinstall the app every time I switch workstations, as the signatures doesn't match or something. I assume the app might remember the old permissions even if it haven't gotten new ones?
compileSdkVersion 27
minSdkVersion 19
targetSdkVersion 27
Why the hell is ActivityCompat.checkSelfPermission() returning true when I have no permissions?
I ask for all the permissions in my MainActivity in the oncreate() method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.INTERNET)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.INTERNET}, 123);
Toast.makeText(this, "This app needs camera and storage permissions", Toast.LENGTH_LONG).show();
}else{
onCreateAfterPermission();
}
}
I then handle the response:
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == 123) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
onCreateAfterPermission();
}else{
// close the app
Toast.makeText(this, "Sorry!!!, you can't use this app without granting permissions", Toast.LENGTH_LONG).show();
this.finish();
}
}
}