- Initialize the ActivityResultLauncher<> variable in onCreate()
// Define an intention to apply for system permissions
var resultLauncher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { it ->
OnActivityResult () = onActivityResult();
Log.i(mTAG, "onViewCreated: ${it},")}Copy the code
The ActivityResultContracts class predefines a variety of system-level intent actions, such as taking photos, opening files, and obtaining permissions
- Open the predefined intent from the previous step.
// Pass in the launch() function the parameters required for the intent defined in the previous step (here refers to the system permission name to apply for)btn.setOnClickListener { resultLauncher? .launch(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.BLUETOOTH)) }Copy the code