permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.
https://github.com/permissions-dispatcher/PermissionsDispatcher
Apache License 2.0
11.22k stars 1.44k forks source link

onRequestPermissionsResult wasen't called on fragment #697

Closed syncended closed 4 years ago

syncended commented 4 years ago

onRequestPermissionsResult wasen't called on fragment. I've called method for start camera preview, and waiting for result, it called permissions, but after denied camera permission nothing was happend

Which library version are you using? (4.8.0) On which devices do you observe the issue? (nexus s API 29)

@RuntimePermissions
class CameraFragment : BaseFragment<FragmentCameraBinding, CameraViewModel>() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setHasOptionsMenu(true)
        getFragmentComponent().inject(this)
        setupViewModel<CameraViewModel>()
//        setupFab(R.drawable.ic_baseline_camera_24, viewModel::onFabClick)
    }

    override fun onCreateBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentCameraBinding {
        return FragmentCameraBinding.inflate(inflater, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        startPreviewWithPermissionCheck()
    }

    @NeedsPermission(Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION)
    fun startPreview() {
        viewModel.startPreview(binding.previewView.surfaceProvider, viewLifecycleOwner)
    }

    @OnPermissionDenied(Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION)
    fun onPermissionsDenied() {
        Snackbar.make(
            binding.root,
            R.string.app_will_not_work_without_permissions,
            Snackbar.LENGTH_LONG
        ).show()
    }
}
hotchemi commented 4 years ago

seems like you have not overridden onRequestPermissionsResult, see the link below.

https://github.com/permissions-dispatcher/PermissionsDispatcher/blob/3a238dad5a27d90b0bf27f22be920a2d6ac968a8/sample/src/main/kotlin/permissions/dispatcher/sample/MainActivity.kt#L30-L34