onRequestPermissionsResult not being called in fragment if defined in both fragment and activity

前端 未结 15 1343
余生分开走
余生分开走 2020-11-28 22:14

I have a fragment in which I have recyclerview and setting data in this recyclerview using recyclerview adapter.

Now, I am having a button in the adapter\'s list ite

15条回答
  •  眼角桃花
    2020-11-28 22:37

    I requested location permission from a fragment and in the fragment, I needed to change this:

                ActivityCompat.requestPermissions(getActivity(), new String[]{
                    Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_REQ_CODE);
    

    to this:

                requestPermissions(new String[]{
                    Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_REQ_CODE);
    

    then the onRequestPermissionsResult was called in the fragment.

提交回复
热议问题