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

前端 未结 10 1106
我寻月下人不归
我寻月下人不归 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:51

    I don't know if it's recently fixed by google, but I can reach the expected result without doing any tricks.

    The most important thing is to call super.onRequestPermissionsResult(requestCode, permissions, grantResults); in the activity, so it will pass the result to fragment if it's requested from fragment.

    So, what I do is:

    1) in fragment, ask permission using v4 fragment.requestPermissions(permissions, requestCode)

    2) in activity's onRequestPermissionsResult, must call super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    3) in fragment's onRequestPermissionsResult, write the code I want to handle the result.

提交回复
热议问题