Android: ActivityCompat.requestPermissions requires activity and not context :/

前端 未结 1 607
离开以前
离开以前 2021-01-12 11:42

I\'m calling ActivityCompat.requestPermissions in order to get permissions under android M, however, this requires an activity in the argument. This would be fine, except th

1条回答
  •  失恋的感觉
    2021-01-12 12:29

    The documentation on requestPermissions says that the activity parameter is the target activity where you want to show the pop up if you haven't included the permission in your manifest and for this purpose that method requires you to pass an activity and not the context, because upon finish the request permissions task it will then return a result to the calling activity(that is the activity passed as the parameter to the method). If you are so adamant about implementing this through your singleton I suggest you create a function that accepts the activity in the parameter and the callbacks too as you WILL need to handle the callbacks if the permissions were given or not

    0 讨论(0)
提交回复
热议问题