-2
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.

RockyGlobal
  • 525
  • 5
  • 13
  • Does this answer your question? [OnActivityResult method is deprecated, what is the alternative?](https://stackoverflow.com/questions/62671106/onactivityresult-method-is-deprecated-what-is-the-alternative) – a_local_nobody May 30 '22 at 12:14
  • This question is related to permission not activity – RockyGlobal May 30 '22 at 12:19
  • how is this different than the link i've provided ? that link i've sent should explain exactly how to convert `onActivityResult`, right ? – a_local_nobody May 30 '22 at 13:46
  • yes but here i don't call activity no intent when i try to specify the intent i am getting type mismatch – RockyGlobal May 30 '22 at 13:57

2 Answers2

0

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
    }
Kishan Mevada
  • 662
  • 1
  • 6
  • 17
  • in second step i am getting type mismatch when specifying intent any suggestion how to specify val intent = onRequestPermissionsResult(requestCode, grantResults) permission.launch(intent) – RockyGlobal May 30 '22 at 12:38
  • Can you suggest for above example if possible it will be easy to understand – RockyGlobal May 30 '22 at 12:43
0
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
}
Gulab Sagevadiya
  • 872
  • 1
  • 8
  • 20