gpt4 book ai didi

Android 在 Android 6.0 中不显示 RECORD_AUDIO 的权限对话框

转载 作者:搜寻专家 更新时间:2023-11-01 09:39:09 24 4
gpt4 key购买 nike

Android 不显示 RECORD_AUDIO 的权限对话框

我已经在android list 中添加了所需的权限

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

和下面的代码

private boolean checkPermission() {
int result = ContextCompat.checkSelfPermission(this, android.Manifest.permission.RECORD_AUDIO);
if (result == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
}

private void requestPermission() {

if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.RECORD_AUDIO)) {
Toast.makeText(this, "RECORD AUDIO Permission is required.",
Toast.LENGTH_LONG).show();

} else {

ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.RECORD_AUDIO},
PERMISSION_REQUEST_CODE);

}
}

并检查它

if (!checkPermission()) {
requestPermission();
}

但是请求权限的对话框或请求权限的屏幕没有显示,

我正在模拟器上测试 android 6.0

最佳答案

ActivityCompat.shouldShowRequestPermissionRationale() 方法仅在应显示消息时发出信号。无论其返回值如何,您都应该请求许可。

查看此示例中的第 142 行:https://developer.android.com/samples/RuntimePermissions/src/com.example.android.system.runtimepermissions/MainActivity.html#l142

/**
* Requests the Camera permission.
* If the permission has been denied previously, a SnackBar will prompt the user to grant the
* permission, otherwise it is requested directly.
*/
private void requestCameraPermission() {
Log.i(TAG, "CAMERA permission has NOT been granted. Requesting permission.");

if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.CAMERA)) {
// Provide an additional rationale to the user if the permission was not granted
// and the user would benefit from additional context for the use of the permission.
// For example if the user has previously denied the permission.
Log.i(TAG,
"Displaying camera permission rationale to provide additional context.");
Snackbar.make(mLayout, R.string.permission_camera_rationale,
Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.CAMERA},
REQUEST_CAMERA);
}
})
.show();
} else {

// Camera permission has not been granted yet. Request it directly.
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA},
REQUEST_CAMERA);
}
}

关于Android 在 Android 6.0 中不显示 RECORD_AUDIO 的权限对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40947466/

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