我正在使用ionic 3
android build apk并尝试从文件中添加图像:///storage/emulated/0/data/io.ionic.vdeovalet/cache/image.jpeg
takePicture(sourceType) {
try {
// Create options for the Camera Dialog
var options = {
quality: 100,destinationType: this.camera.DestinationType.FILE_URI,encodingType: this.camera.EncodingType.JPEG,sourceType: sourceType,};
this.camera.getPicture(options).then((imagePath) => {
// Special handling for Android library
if (this.platform.is('android') && sourceType ===
this.camera.PictureSourceType.PHOTOLIBRARY) {
this.filePath.resolveNativePath(imagePath)
.then(filePath => {
let correctPath = filePath.substr(0,filePath.lastIndexOf('/') + 1);
let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1,imagePath.lastIndexOf('?'));
this.copyFileToLocalDir(correctPath,currentName,this.createFileName());
this.lastImage = filePath;
});
} else {
var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
var correctPath = imagePath.substr(0,imagePath.lastIndexOf('/') + 1);
this.copyFileToLocalDir(correctPath,this.createFileName());
}
},(err) => {
this.presentToast('Error while selecting image.');
});
} catch (e) {
console.error(e);
}
}
错误:不允许加载本地资源
android 6.0.1
Ionic 3 Android: 图片选择问题与本地资源加载限制
本文探讨了在使用Ionic 3构建Android应用时,如何通过Camera API从相册获取图片,但遇到在Android 6.0.1及以后版本中加载本地资源的权限问题。作者提供了针对Android平台特定处理的解决方案,包括路径转换和文件复制。
240

被折叠的 条评论
为什么被折叠?



