gpt4 book ai didi

android - 运行时权限 : shouldshowrequestpermissionrationale always returns false

转载 作者:行者123 更新时间:2023-12-04 23:58:12 40 4
gpt4 key购买 nike

下面是我的代码,我调用此代码以获得运行时权限。在这种情况下,“shouldshowrequestpermissionrationale 总是返回 false”。我找不到解决方案为什么会这样。因此,未显示运行时权限警报。请给我一个解决方案...

   private void checkRuntimePermission() {

Logger.infoLog("checkRuntimePermission");
if(ActivityCompat.checkSelfPermission(this, permissionsRequired[0]) != PackageManager.PERMISSION_GRANTED){
Logger.infoLog("checkRuntimePermission first if");
if(ActivityCompat.shouldShowRequestPermissionRationale(WelcomeActivity.this,permissionsRequired[0])){
Logger.infoLog("checkRuntimePermission if");
//just request the permission
//Show Information about why you need the permission
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Need Multiple Permissions");
builder.setMessage("This app needs Camera and Location permissions.");
builder.setPositiveButton("Grant", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
ActivityCompat.requestPermissions(WelcomeActivity.this,permissionsRequired,PERMISSION_CALLBACK_CONSTANT);
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}else{
Logger.infoLog("Show request permission rationale false");
}
} else {
//You already have the permission, just go ahead.
Logger.infoLog("Permission given already");
proceedAfterPermission();
}
}

最佳答案

在谷歌文档中:

"This method returns true if the app has requested this permission previously and the user denied the request."



所以,你应该调用 请求权限(...) 首先,然后使用 应该ShowRequestPermissionRationale(...) 可以得到你想要的结果。

最好的方法是始终使用 请求权限(...) onRequestPermissionsResult(...)

关于android - 运行时权限 : shouldshowrequestpermissionrationale always returns false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45684842/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com