Android M Permissions:onRequestPermissionsResult()未被调用 [英] Android M Permissions: onRequestPermissionsResult() not being called
问题描述
我正在更新我们的应用以使用新的M权限系统。
除了onRequestPermissionsResult()之外,它都在工作。我需要在按下按钮时检查权限,如果成功,则发送短信。当我授予这样做的权限时,对话框会关闭,但在我再次按下按钮之前它不会触发发送文本。
I'm updating our app to use the new M Permissions system. It is all working besides the onRequestPermissionsResult(). I need to check a permission on a button press, and if it is successful, send a text message. When I grant permission to do it, the dialog closes, but it doesn't trigger the Send Text until I press the button again.
我已经调试并设置了断点在onRequestPermissionsResult()方法中,它永远不会进入它。
I've debugged and set breakpoints in the onRequestPermissionsResult() method but it never goes into it.
首先调用此方法:
private void askForPermission() {
String[] permissions = new String[]{Manifest.permission.SEND_SMS};
ActivityCompat.requestPermissions(getActivity(), permissions, PERMISSIONS_CODE);
}
然后我的回调如下:
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSIONS_CODE) {
for (int i = 0; i < permissions.length; i++) {
String permission = permissions[i];
int grantResult = grantResults[i];
if (permission.equals(Manifest.permission.SEND_SMS)) {
if (grantResult == PackageManager.PERMISSION_GRANTED) {
onPPSButtonPress();
} else {
requestPermissions(new String[]{Manifest.permission.SEND_SMS}, PERMISSIONS_CODE);
}
}
}
}
}
有没有人遇到过类似的问题?
感谢任何帮助。
谢谢
Has anybody ran into a similar issue? Appreciate any help with this. Thanks
推荐答案
这个问题实际上是由NestedFragments引起的。
基本上大多数片段我们都扩展了一个HostedFragment,后者又扩展了CompatFragment。拥有这些嵌套的片段导致问题最终由项目上的另一个开发人员解决。
This issue was actually being caused by NestedFragments. Basically most fragments we have extend a HostedFragment which in turn extends a CompatFragment. Having these nested fragments caused issues which eventually were solved by another developer on the project.
他正在做一些低级别的东西,比如切换到让这个工作,所以我是不太确定实际的最终解决方案
He was doing some low level stuff like bit switching to get this working so I'm not too sure of the actual final solution
这篇关于Android M Permissions:onRequestPermissionsResult()未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!