Created
March 12, 2016 16:01
-
-
Save elcioabrahao/7a1f18b08eb252ccf2dd to your computer and use it in GitHub Desktop.
Exemplo de código para solicitar permissões no Android M (6.0 Marchmellow)
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
// Exemplo de chamada: | |
requestPermissions(); | |
@Override | |
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | |
switch (requestCode){ | |
case REQUEST_CODE_PERMISSION: | |
if(grantResults[0] == PackageManager.PERMISSION_GRANTED){ | |
//fazer o necessário | |
}else if(grantResults[0] == PackageManager.PERMISSION_DENIED){ | |
//TODO tratar em caso de Denied | |
} | |
if(grantResults[1] == PackageManager.PERMISSION_GRANTED){ | |
Log.i("CAMERA PERMISSION", "GRANTED"); | |
}else if(grantResults[1] == PackageManager.PERMISSION_DENIED){ | |
//TODO tratar em caso de Denied | |
} | |
break; | |
default: | |
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |
} | |
} | |
@TargetApi(Build.VERSION_CODES.M) | |
private void requestPermissions(){ | |
String[] perms = { Manifest.permission.READ_CONTACTS , Manifest.permission.CAMERA}; | |
int hasReadSMSPermission = checkSelfPermission(Manifest.permission.READ_CONTACTS); | |
if(hasReadSMSPermission != PackageManager.PERMISSION_GRANTED){ | |
requestPermissions(perms, REQUEST_CODE_PERMISSION); | |
return; | |
} | |
startManageLocalContactsJob(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment