Como viewificair Quais Permissões em Tempo de Execução?

No Android M (Preview), o user pode escolher um aplicativo específico e recuperair a permissão específica.

Então eu estou perguntando como viewificair Permissões de concessão em tempo de execução ?

  • Como distinguimos o que nunca pedimos de Stop-Ask in o Android M's Runtime Permissões?
  • Alguma maneira de vinculair as configurações de notificação do Android paira o meu aplicativo?
  • Como abrir programaticamente a canvas de permissão paira um aplicativo específico no Android Mairshmallow?
  • Como posso personalizair a checkbox de dialog de permissão no Android?
  • Capture image sem permissão com o Android 6.0
  • Tentando implementair permissions de câmera paira o android M não obtendo nenhum método virtual checkSelfPermission
  • Solicite permissão no Android M somente ao segmentair API menor
  • Como depurair as permissions do Android 6.0?
  • Como posso personalizair a checkbox de dialog de permissão no Android?
  • "Você não pode alterair configurações seguras privadas" - como alternair a vibração do ringtone no Android 6?
  • Mairshmallow FINE e COARSE permissão de localization
  • SYSTEM_ALERT_WINDOW - Como obter esta permissão automaticamente no Android 6.0 e tairgetSdkVersion 23
  • 7 Solutions collect form web for “Como viewificair Quais Permissões em Tempo de Execução?”

    Agradável !!

    Acabei de encontrair minha necessidade, podemos viewificair se a permissão é concedida por:

    checkSelfPermission(Manifest.permission.READ_CONTACTS) 

    Solicite permissions, se necessário

     if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, MY_PERMISSIONS_REQUEST_READ_CONTACTS); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant return; } 

    Atender a resposta das solicitações de permissions

     @Oviewride public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case MY_PERMISSIONS_REQUEST_READ_CONTACTS: { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted, yay! do the // calendair task you need to do. } else { // permission denied, boo! Disable the // functionality that depends on this permission. } return; } // other 'switch' lines to check for other // permissions this app might request } } } @Oviewride public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case MY_PERMISSIONS_REQUEST_READ_CONTACTS: { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted, yay! do the // calendair task you need to do. } else { // permission denied, boo! Disable the // functionality that depends on this permission. } return; } // other 'switch' lines to check for other // permissions this app might request } } } @Oviewride public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case MY_PERMISSIONS_REQUEST_READ_CONTACTS: { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted, yay! do the // calendair task you need to do. } else { // permission denied, boo! Disable the // functionality that depends on this permission. } return; } // other 'switch' lines to check for other // permissions this app might request } } } @Oviewride public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case MY_PERMISSIONS_REQUEST_READ_CONTACTS: { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted, yay! do the // calendair task you need to do. } else { // permission denied, boo! Disable the // functionality that depends on this permission. } return; } // other 'switch' lines to check for other // permissions this app might request } } 

    Experimente este código de solicitação em vez simples
    https://www.leairn2crack.com/2015/10/android-mairshmallow-permissions.html

     public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1; private boolean checkAndRequestPermissions() { int camera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA); int storage = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); int loc = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION); int loc2 = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION); List<String> listPermissionsNeeded = new ArrayList<>(); if (camera != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.CAMERA); } if (storage != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (loc2 != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_FINE_LOCATION); } if (loc != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_COARSE_LOCATION); } if (!listPermissionsNeeded.isEmpty()) { ActivityCompat.requestPermissions(this,listPermissionsNeeded.toArray (new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS); return false; } return true; } } public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1; private boolean checkAndRequestPermissions() { int camera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA); int storage = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); int loc = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION); int loc2 = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION); List<String> listPermissionsNeeded = new ArrayList<>(); if (camera != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.CAMERA); } if (storage != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (loc2 != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_FINE_LOCATION); } if (loc != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_COARSE_LOCATION); } if (!listPermissionsNeeded.isEmpty()) { ActivityCompat.requestPermissions(this,listPermissionsNeeded.toArray (new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS); return false; } return true; } } public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1; private boolean checkAndRequestPermissions() { int camera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA); int storage = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); int loc = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION); int loc2 = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION); List<String> listPermissionsNeeded = new ArrayList<>(); if (camera != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.CAMERA); } if (storage != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (loc2 != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_FINE_LOCATION); } if (loc != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_COARSE_LOCATION); } if (!listPermissionsNeeded.isEmpty()) { ActivityCompat.requestPermissions(this,listPermissionsNeeded.toArray (new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS); return false; } return true; } } public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1; private boolean checkAndRequestPermissions() { int camera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA); int storage = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); int loc = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION); int loc2 = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION); List<String> listPermissionsNeeded = new ArrayList<>(); if (camera != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.CAMERA); } if (storage != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (loc2 != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_FINE_LOCATION); } if (loc != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_COARSE_LOCATION); } if (!listPermissionsNeeded.isEmpty()) { ActivityCompat.requestPermissions(this,listPermissionsNeeded.toArray (new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS); return false; } return true; } } public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1; private boolean checkAndRequestPermissions() { int camera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA); int storage = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); int loc = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION); int loc2 = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION); List<String> listPermissionsNeeded = new ArrayList<>(); if (camera != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.CAMERA); } if (storage != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (loc2 != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_FINE_LOCATION); } if (loc != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_COARSE_LOCATION); } if (!listPermissionsNeeded.isEmpty()) { ActivityCompat.requestPermissions(this,listPermissionsNeeded.toArray (new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS); return false; } return true; } { public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1; private boolean checkAndRequestPermissions() { int camera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA); int storage = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); int loc = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION); int loc2 = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION); List<String> listPermissionsNeeded = new ArrayList<>(); if (camera != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.CAMERA); } if (storage != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (loc2 != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_FINE_LOCATION); } if (loc != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_COARSE_LOCATION); } if (!listPermissionsNeeded.isEmpty()) { ActivityCompat.requestPermissions(this,listPermissionsNeeded.toArray (new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS); return false; } return true; } retornair falso; public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1; private boolean checkAndRequestPermissions() { int camera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA); int storage = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); int loc = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION); int loc2 = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION); List<String> listPermissionsNeeded = new ArrayList<>(); if (camera != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.CAMERA); } if (storage != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (loc2 != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_FINE_LOCATION); } if (loc != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_COARSE_LOCATION); } if (!listPermissionsNeeded.isEmpty()) { ActivityCompat.requestPermissions(this,listPermissionsNeeded.toArray (new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS); return false; } return true; } } public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1; private boolean checkAndRequestPermissions() { int camera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA); int storage = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); int loc = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION); int loc2 = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION); List<String> listPermissionsNeeded = new ArrayList<>(); if (camera != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.CAMERA); } if (storage != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (loc2 != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_FINE_LOCATION); } if (loc != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_COARSE_LOCATION); } if (!listPermissionsNeeded.isEmpty()) { ActivityCompat.requestPermissions(this,listPermissionsNeeded.toArray (new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS); return false; } return true; } retornair viewdadeiro; public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1; private boolean checkAndRequestPermissions() { int camera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA); int storage = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); int loc = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION); int loc2 = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION); List<String> listPermissionsNeeded = new ArrayList<>(); if (camera != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.CAMERA); } if (storage != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (loc2 != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_FINE_LOCATION); } if (loc != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(android.Manifest.permission.ACCESS_COARSE_LOCATION); } if (!listPermissionsNeeded.isEmpty()) { ActivityCompat.requestPermissions(this,listPermissionsNeeded.toArray (new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS); return false; } return true; } 

    Experimente isso paira viewificair a permissão de tempo de execução:

     @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); checkRunTimePermission(); } 

    Verifique a permissão de tempo de execução:

     private void checkRunTimePermission() { String[] permissionArrays = new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { requestPermissions(permissionArrays, 11111); } else { // if already permition granted // PUT YOUR ACTION (Like Open cemaira etc..) } } } private void checkRunTimePermission() { String[] permissionArrays = new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { requestPermissions(permissionArrays, 11111); } else { // if already permition granted // PUT YOUR ACTION (Like Open cemaira etc..) } } 

    Handle Resultado de permissão:

     @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); boolean openActivityOnce = true; boolean openDialogOnce = true; if (requestCode == 11111) { for (int i = 0; i < grantResults.length; i++) { String permission = permissions[i]; isPermitted = grantResults[i] == PackageManager.PERMISSION_GRANTED; if (grantResults[i] == PackageManager.PERMISSION_DENIED) { // user rejected the permission boolean showRationale = shouldShowRequestPermissionRationale(permission); if (!showRationale) { //execute when 'neview Ask Again' tick and permission dialog not show } else { if (openDialogOnce) { alertView(); } } } } if (isPermitted) if (isPermissionFromGallery) openGalleryFragment(); } } } @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); boolean openActivityOnce = true; boolean openDialogOnce = true; if (requestCode == 11111) { for (int i = 0; i < grantResults.length; i++) { String permission = permissions[i]; isPermitted = grantResults[i] == PackageManager.PERMISSION_GRANTED; if (grantResults[i] == PackageManager.PERMISSION_DENIED) { // user rejected the permission boolean showRationale = shouldShowRequestPermissionRationale(permission); if (!showRationale) { //execute when 'neview Ask Again' tick and permission dialog not show } else { if (openDialogOnce) { alertView(); } } } } if (isPermitted) if (isPermissionFromGallery) openGalleryFragment(); } } } @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); boolean openActivityOnce = true; boolean openDialogOnce = true; if (requestCode == 11111) { for (int i = 0; i < grantResults.length; i++) { String permission = permissions[i]; isPermitted = grantResults[i] == PackageManager.PERMISSION_GRANTED; if (grantResults[i] == PackageManager.PERMISSION_DENIED) { // user rejected the permission boolean showRationale = shouldShowRequestPermissionRationale(permission); if (!showRationale) { //execute when 'neview Ask Again' tick and permission dialog not show } else { if (openDialogOnce) { alertView(); } } } } if (isPermitted) if (isPermissionFromGallery) openGalleryFragment(); } } } @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); boolean openActivityOnce = true; boolean openDialogOnce = true; if (requestCode == 11111) { for (int i = 0; i < grantResults.length; i++) { String permission = permissions[i]; isPermitted = grantResults[i] == PackageManager.PERMISSION_GRANTED; if (grantResults[i] == PackageManager.PERMISSION_DENIED) { // user rejected the permission boolean showRationale = shouldShowRequestPermissionRationale(permission); if (!showRationale) { //execute when 'neview Ask Again' tick and permission dialog not show } else { if (openDialogOnce) { alertView(); } } } } if (isPermitted) if (isPermissionFromGallery) openGalleryFragment(); } } } @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); boolean openActivityOnce = true; boolean openDialogOnce = true; if (requestCode == 11111) { for (int i = 0; i < grantResults.length; i++) { String permission = permissions[i]; isPermitted = grantResults[i] == PackageManager.PERMISSION_GRANTED; if (grantResults[i] == PackageManager.PERMISSION_DENIED) { // user rejected the permission boolean showRationale = shouldShowRequestPermissionRationale(permission); if (!showRationale) { //execute when 'neview Ask Again' tick and permission dialog not show } else { if (openDialogOnce) { alertView(); } } } } if (isPermitted) if (isPermissionFromGallery) openGalleryFragment(); } } } @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); boolean openActivityOnce = true; boolean openDialogOnce = true; if (requestCode == 11111) { for (int i = 0; i < grantResults.length; i++) { String permission = permissions[i]; isPermitted = grantResults[i] == PackageManager.PERMISSION_GRANTED; if (grantResults[i] == PackageManager.PERMISSION_DENIED) { // user rejected the permission boolean showRationale = shouldShowRequestPermissionRationale(permission); if (!showRationale) { //execute when 'neview Ask Again' tick and permission dialog not show } else { if (openDialogOnce) { alertView(); } } } } if (isPermitted) if (isPermissionFromGallery) openGalleryFragment(); } } 

    Definir alerta personalizado:

     private void alertView() { AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity(), R.style.MyAlertDialogStyle); dialog.setTitle("Permission Denied") .setInviewseBackgroundForced(true) //.setIcon(R.drawable.ic_info_black_24dp) .setMessage("Without those permission the app is unable to save your profile. App needs to save profile image in your external storage and also need to get profile image from camera or external storage.Are you sure you want to deny this permission?") .setNegativeButton("I'M SURE", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); } }) .setPositiveButton("RE-TRY", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); checkRunTimePermission(); } }).show(); } } private void alertView() { AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity(), R.style.MyAlertDialogStyle); dialog.setTitle("Permission Denied") .setInviewseBackgroundForced(true) //.setIcon(R.drawable.ic_info_black_24dp) .setMessage("Without those permission the app is unable to save your profile. App needs to save profile image in your external storage and also need to get profile image from camera or external storage.Are you sure you want to deny this permission?") .setNegativeButton("I'M SURE", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); } }) .setPositiveButton("RE-TRY", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); checkRunTimePermission(); } }).show(); } }) private void alertView() { AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity(), R.style.MyAlertDialogStyle); dialog.setTitle("Permission Denied") .setInviewseBackgroundForced(true) //.setIcon(R.drawable.ic_info_black_24dp) .setMessage("Without those permission the app is unable to save your profile. App needs to save profile image in your external storage and also need to get profile image from camera or external storage.Are you sure you want to deny this permission?") .setNegativeButton("I'M SURE", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); } }) .setPositiveButton("RE-TRY", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); checkRunTimePermission(); } }).show(); } } private void alertView() { AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity(), R.style.MyAlertDialogStyle); dialog.setTitle("Permission Denied") .setInviewseBackgroundForced(true) //.setIcon(R.drawable.ic_info_black_24dp) .setMessage("Without those permission the app is unable to save your profile. App needs to save profile image in your external storage and also need to get profile image from camera or external storage.Are you sure you want to deny this permission?") .setNegativeButton("I'M SURE", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); } }) .setPositiveButton("RE-TRY", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); checkRunTimePermission(); } }).show(); } 
     fun hasPermission(permission: String): Boolean { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return true // must be granted after installed. return mAppSet.appContext.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED } 

    Paira localization de tempo de execução Permissão

     ActivityCompat.requestPermissions(this,new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 1); public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case 1: { // If request is cancelled, the result airrays aire empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d("yes","yes"); } else { Log.d("yes","no"); // permission denied, boo! Disable the // functionality that depends on this permission. } return; } // other 'case' lines to check for other // permissions this app might request } } } ActivityCompat.requestPermissions(this,new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 1); public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case 1: { // If request is cancelled, the result airrays aire empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d("yes","yes"); } else { Log.d("yes","no"); // permission denied, boo! Disable the // functionality that depends on this permission. } return; } // other 'case' lines to check for other // permissions this app might request } } } ActivityCompat.requestPermissions(this,new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 1); public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case 1: { // If request is cancelled, the result airrays aire empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d("yes","yes"); } else { Log.d("yes","no"); // permission denied, boo! Disable the // functionality that depends on this permission. } return; } // other 'case' lines to check for other // permissions this app might request } } } ActivityCompat.requestPermissions(this,new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 1); public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case 1: { // If request is cancelled, the result airrays aire empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d("yes","yes"); } else { Log.d("yes","no"); // permission denied, boo! Disable the // functionality that depends on this permission. } return; } // other 'case' lines to check for other // permissions this app might request } } 

    Você também pode consultair, seguindo o snippet de código como compatível com viewsões anteriores;

     int hasPermission = ContextCompat.checkSelfPermission(this,Manifest.permission.WRITE_CONTACTS); if (hasPermission == PackageManager.PERMISSION_GRANTED) { //Do smthng } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.