[英]How to get permissions to access the Android Image Gallery in React-Native?
使用图像选择器,我的应用程序可以使用以下代码成功访问 iOS 相机胶卷:
getPermissionAsync = async () => {
if (Constants.platform.ios) {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status !== 'granted') {
alert('Sorry, you must grant camera roll permissions in order to do this.');
}
}
if (Constants.platform.android) {
const { statusA } = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA);
if (statusA !== PermissionsAndroid.RESULTS.GRANTED) {
alert('Sorry, you must grant camera roll permissions in order to do this.');
}
}
};
但是,它不适用于 Android。 谁能告诉我如何获得访问 android 设备上的图片库的权限?
谢谢
在 AndroidManifest.xml 文件中使用以下代码
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
并使用 react-native-image-crop-picker package,我认为它更好
https://github.com/ivpusic/react-native-image-crop-picker
我希望这是你的答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.