override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
onRequestPermissionsResult(requestCode, grantResults)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == Consts.LocationService.REQUEST_LOCATION) {
locationHelper.onActivityResult(requestCode)
}
}
let me know how to convert the above block of code to new way
'onActivityResult(Int, Int, Intent?): Unit' is deprecated.
CodePudding user response:
Step 1 :
private val fileChooserIntent: Intent
get() {
val mimeTypes = arrayOf("*/*")
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.type = "*/*"
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
return intent
}
Step 2 :
val intent = fileChooserIntent
fileChooseActivity.launch(intent)
Step 3 :
private var fileChooseActivity = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result: ActivityResult ->
// Your On Activity Result
}
CodePudding user response:
implementation 'com.androidisland.ezpermission:ezpermission:0.1.4'
This lib is helpful and Easy to use
EzPermission.with(this).permissions(permissions).request {
granted: Set<String>,
denied: Set<String>,
permanentlyDenied: Set<String> ->
// Do what ever after getting request
}