Fix crash onPermissionResult before any permission request

This commit is contained in:
Schoumi 2017-08-25 11:51:12 +02:00
parent ed9f00bab2
commit 83e7ac84fc
2 changed files with 4 additions and 4 deletions

View File

@ -7,8 +7,8 @@ android {
applicationId "fr.mobdev.blooddonation"
minSdkVersion 17
targetSdkVersion 26
versionCode = 10
versionName = "3.2"
versionCode = 11
versionName = "3.3"
}
buildTypes {
release {

View File

@ -134,14 +134,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(requestCode == 1 && (grantResults[0] == PackageManager.PERMISSION_GRANTED || grantResults[1] == PackageManager.PERMISSION_GRANTED)) {
if(requestCode == 1 && grantResults.length == 2 && (grantResults[0] == PackageManager.PERMISSION_GRANTED || grantResults[1] == PackageManager.PERMISSION_GRANTED)) {
FragmentManager manager = getFragmentManager();
Fragment frag = manager.findFragmentById(R.id.fragment_container);
if(frag instanceof MapsFragment) {
((MapsFragment)frag).startUpdateLocations();
}
}
if(requestCode == 2 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
if(requestCode == 2 && grantResults.length == 1 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this,R.string.need_write,Toast.LENGTH_LONG).show();
}
}