Skip to content

Instantly share code, notes, and snippets.

@davidelp68
Created September 6, 2020 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidelp68/538128577781c788385cb95733a08246 to your computer and use it in GitHub Desktop.
Save davidelp68/538128577781c788385cb95733a08246 to your computer and use it in GitHub Desktop.
Android Studio - Permessi
//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