Request runtime permissions from v4.Fragment and have callback go to Fragment?

前端 未结 10 1101
我寻月下人不归
我寻月下人不归 2020-12-01 01:35

I\'m having a weird issue that is causing a conflict. I had to switch to native Fragments to fix it, but there are bugs with that.

My original problem:

10条回答
  •  无人及你
    2020-12-01 01:43

    In my case I have requested the permission from the fragment and also need to get the response in fragment.

    But my phone running on android 8.1

    so I was need to add one more condition for check this

    so eventually there is my solution

    private void doOnWazeButtonClick()
    {
        int permissionStatus = PackageManager.PERMISSION_DENIED;
    
        if (getContext() != null)
        {
            permissionStatus = ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION);
        }
    
        if (permissionStatus == PackageManager.PERMISSION_GRANTED)
        {
            showContentWaze();
        }
        else
        {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            {
                Objects.requireNonNull(getActivity()).requestPermissions(new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE_PERMISSION_ACCESS_FINE_LOCATION);
            }
            else
            {
                requestPermissions(new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE_PERMISSION_ACCESS_FINE_LOCATION);
            }
        }
    }
    

提交回复
热议问题