https://juejin.cn/post/6925818114974154765
React Hook 中 createContext & useContext 跨组件透传上下文与性能优化
注意:
从 Android 6.0(API 级别 23)开始,用户在应用运行时授予应用权限,而不是在安装应用时授予权限。因此添加权限AndroidManifest.xml不适用于 Android 6.0+ 设备。要在运行时授予权限,您可以使用PermissionAndroid API。
if (Platform.OS === 'android') {
requestStorePermission();
}
......
const requestStorePermission = async () => {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: 'Storage',
message: 'This app would like to store some files on your phone',
// buttonNeutral: "message..",
// buttonNegative: "No",
buttonPositive: "Yes"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) { // 已授权
......
}
}
|