0
override fun onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<out String>,
    grantResults: IntArray
) {
    // super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    Log.wtf("here grand result" , requestCode.toString(),)
    Log.wtf("here grand result" , grantResults.toString(),)

    if(requestCode == PERMISSION_REQUEST_ACCESS_LOCATION){

        if(grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED){
            Toast.makeText(requireActivity(),"permission granted",Toast.LENGTH_SHORT).show()
            getUserLocation()
        }else{
            Toast.makeText(requireActivity(),"Denied",Toast.LENGTH_SHORT).show()
        }
    }
}

I am always get the auto toast message from here but when location granted then i wants to call a function but this override method not working inside fragment please help me ? Thanks in advance

Sajib saha
  • 301
  • 4
  • 16

1 Answers1

0

Use below code to call onRequestPermissionResult method in fragment

requestPermisions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION, LOCATION_PERMISSION_REQUEST_CODE}

Don't use ActivityCompat.requestPermission because it should called from activity only not in fragment.

Jaydeep parmar
  • 561
  • 2
  • 15