Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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