Created
September 6, 2020 13:44
-
-
Save davidelp68/538128577781c788385cb95733a08246 to your computer and use it in GitHub Desktop.
Android Studio - Permessi
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
//funzione che recupera la scelta fatta nei permessi | |
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String?>, grantResults: IntArray) { | |
if (grantResults.isNotEmpty() && grantResults[0] == | |
PackageManager.PERMISSION_GRANTED) { | |
//inserire qui il codice da eseguire se i permessi sono concessi | |
Toast.makeText(this, "Premessi concessi", Toast.LENGTH_SHORT).show() | |
} | |
else | |
{ | |
if (ActivityCompat.shouldShowRequestPermissionRationale(this, | |
Manifest.permission.WRITE_EXTERNAL_STORAGE)) { | |
//inserire qui il codice da eseguire se l'utente ha negato il permesso (ma non in modo permanente) | |
Toast.makeText(this, "Premessi rifiutati in modo temporaneo", Toast.LENGTH_SHORT).show() | |
} | |
else { | |
//inserire qui il codice da eseguire se l'utente ha negato il permesso (in modo permanente) | |
//cioè è stato selezionato il CheckBox " | |
snackBar = Snackbar.make(root_layout, """Hai rifiutato questa autorizzazione. | |
Devi approvare nelle impostazioni dell'app.""", Snackbar.LENGTH_LONG) | |
snackBar!!.setAction("Imposta", View.OnClickListener { | |
//inserire il codice che deve essere eseguito quando si preme il pulsante | |
//all'interno della SnackBar | |
startActivity(Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:com.dm.tutorialpermission7"))) | |
}) | |
snackBar!!.show() | |
} | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment