Last active
September 30, 2018 09:15
-
-
Save davidgassner/91269c304197017be1f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Add before making a phone call | |
if (ActivityCompat.checkSelfPermission( | |
MainActivity.this, Manifest.permission.CALL_PHONE) | |
!= PackageManager.PERMISSION_GRANTED) { | |
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, | |
Manifest.permission.CALL_PHONE)) { | |
Toast.makeText(MainActivity.this, "I know you said no, but I'm asking again", Toast.LENGTH_SHORT).show(); | |
} | |
ActivityCompat.requestPermissions(MainActivity.this, | |
new String[]{Manifest.permission.CALL_PHONE}, | |
MY_PERMISSIONS_REQUEST_CALL_PHONE); | |
return; | |
} | |
//End of addition | |
//Add this method to handle the result of the permission request | |
@Override | |
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | |
switch (requestCode) { | |
case MY_PERMISSIONS_REQUEST_CALL_PHONE: { | |
if (grantResults.length > 0 | |
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |
Toast.makeText(MainActivity.this, "Permission was granted!", | |
Toast.LENGTH_SHORT).show(); | |
callForInfo(); | |
} else { | |
Toast.makeText(MainActivity.this, "Permission was denied!", | |
Toast.LENGTH_SHORT).show(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment