我根据新材料设计集成了marshmallow权限对话框,但权限对话框正在模拟器上工作但不在真实设备上。而且我也没有收到任何错误。任何人都可以帮帮我吗?
我使用下面的代码: -
ActivityCompat.requestPermissions(此, new String [] {Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_LOCATION);
答案 0 :(得分:1)
我这样做对你来说可能有用
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CALL_PHONE) && ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_PHONE_STATE)) {
showDialogOK("Phone State & Call Phone Services Permission required for this app",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
checkAndRequestPermissions();
break;
case DialogInterface.BUTTON_NEGATIVE:
// proceed with logic by disabling the related features or quit the app.
finish();
break;
}
}
});
}
showDialog方法及其为CALL_PHONE和READ_PHONE_STATE工作
private void showDialogOK(String message, DialogInterface.OnClickListener okListener) {
new AlertDialog.Builder(this)
.setMessage(message)
.setPositiveButton("OK", okListener)
.setNegativeButton("Cancel", okListener)
.create()
.show();
}
答案 1 :(得分:1)
这不是您的代码的问题....
我遇到了同样的问题,并且能够在a similar stackoverflow post的帮助下修复它。
强制停止this application会使权限对话框允许按钮再次起作用。