Runtime Permission on android marshmallow

别说谁变了你拦得住时间么 提交于 2019-12-25 07:46:34

问题


I would like to know whether the runtime permission popup is visible or not in the activity. How can i know that? Is there any callback or overrided method for the same.


回答1:


You request permissions yourself so you know when it is shown. You can also add a result callback. See the code below;

public void requestPermissions(List<String> permissions, ActivityCompat.OnRequestPermissionsResultCallback onRequestPermissionsResultCallback) {
    String[] params = permissions.toArray(new String[permissions.size()]);
    requestPermissions(params, onRequestPermissionsResultCallback);
}

public void requestPermissions(String[] permissions, ActivityCompat.OnRequestPermissionsResultCallback onRequestPermissionsResultCallback) {
    this.onRequestPermissionsResultCallback = onRequestPermissionsResultCallback;
    ActivityCompat.requestPermissions(this, permissions, REQUEST_CODE_PERMISSIONS);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == REQUEST_CODE_PERMISSIONS && onRequestPermissionsResultCallback != null) {
        this.onRequestPermissionsResultCallback.onRequestPermissionsResult(requestCode, permissions, grantResults);
        this.onRequestPermissionsResultCallback = null;
    }
}

This would generally sit inside some kind of base Activity class.



来源:https://stackoverflow.com/questions/36311448/runtime-permission-on-android-marshmallow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!