此处显示有关如何在react native中使用PersmissionAndroid的示例: https://facebook.github.io/react-native/docs/permissionsandroid
import { PermissionsAndroid } from 'react-native';
async function requestCameraPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CAMERA,
{
'title': 'Cool Photo App Camera Permission',
'message': 'Cool Photo App needs access to your camera ' +
'so you can take awesome pictures.'
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("You can use the camera")
} else {
console.log("Camera permission denied")
}
} catch (err) {
console.warn(err)
}
}
如何知道此对话框是否真正显示?由于有时用户已经批准了该权限,并且下次调用此功能时,它将不再显示,而仅返回授予的结果。
如何知道用户是否确实单击了“拒绝”和“允许”按钮?