Created
March 2, 2022 20:22
-
-
Save raystatic/49fe15cf0493ee087846024f09c57a97 to your computer and use it in GitHub Desktop.
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
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