我使用 Nammu来询问和授予用户权限。
我去了这段代码:
@Override
public void onClick(View v) {
if (v.equals(myButton)) {
Nammu.init(getActivity());
if (Nammu.checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
//Its ok, do stuff here...
} else {
//Asking for permission
//Third parameter is *this* Fragment. So the callbacks should fire here, in this class instance. Which is a Fragment.
Nammu.askForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, this);
}
}
在我所拥有的片段中:
@Override
public void permissionGranted() {
Log.i("perm_is_granted", "yes, granted");
}
@Override
public void permissionRefused() {
Log.i("perm_is_granted", "no, refused");
}
问题:
这两个回调函数永远不会被调用。 我做错了什么?
答案 0 :(得分:4)
你是否重写了活动中的“onRequestPermissionsResult”方法? https://github.com/tajchert/Nammu#easy-asking-for-permissions