Skip to content

Instantly share code, notes, and snippets.

@raystatic
Created March 2, 2022 20:22
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 raystatic/49fe15cf0493ee087846024f09c57a97 to your computer and use it in GitHub Desktop.
Save raystatic/49fe15cf0493ee087846024f09c57a97 to your computer and use it in GitHub Desktop.
class MainActivity : ComponentActivity() {
private lateinit var requestMultiplePermission: ActivityResultLauncher<Array<String>>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestMultiplePermission = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
){
var isGranted = false
it.forEach { s, b ->
isGranted = b
}
if (!isGranted){
Toast.makeText(this, "Permission Not Granted", Toast.LENGTH_SHORT).show()
}
}
setContent {
DownloadFileWorkManagerDemoTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
requestMultiplePermission.launch(
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
)
Home()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment