If you look at the documentation for the requestPermissions fragment method, you will find that you still need to declare permissions in your manifest:

If this is not the case, then the own onRequestPermissionsResult fragment will not be called.
Instead, the onRequestPermissionsResult action is onRequestPermissionsResult but will not have any effect.
So permission resolution inside the fragment should be done as follows:
1. Declare permission in your manifest
<uses-permission android:name="android.permission.CAMERA"/>
Enter this before the application tag.
2. Check the resolution in your fragment
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { requestPermissions( arrayOf(Manifest.permission.CAMERA), REQUEST_CODE_CAMERA_PERMISSION) }
3. Wait for the resolution result in your fragment
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { when (requestCode) { REQUEST_CODE_CAMERA_PERMISSION -> { val granted = grantResults.isNotEmpty() && permissions.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED && !ActivityCompat.shouldShowRequestPermissionRationale(activity, permissions[0]) when (granted) { true -> openCamera() else -> proceedWithoutPermission() } } }
4. Make sure you do not override the onRequestPermissionsResult action
Overriding the onRequestPermissionsResult activity will cause the fragment to not respond.
Nino Handler Oct 24 '18 at 19:34 2018-10-24 19:34
source share