android – cordova相机插件获取所选图像的真实路径

android – cordova相机插件获取所选图像的真实路径,第1张

概述var options = { quality: 30, destinationType: Camera.DestinationType.FILE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY,};navigator.camera.getPicture( function(imageURI) {
var options = {    quality: 30,destinationType: Camera.DestinationType.file_URI,sourceType: Camera.PictureSourceType.PHOTOliBRARY,};navigator.camera.getPicture(    function(imageURI) {        window.resolveLocalfileSystemURL(imageURI,function(fileEntry) {            console.log(fileEntry.toURI());            scope.$apply(function() {                    ctrl.$setVIEwValue(fileEntry.fullPath);            });        },function(err){            console.log(err);        });     },function(err) {        console.log(err);    },options);

imageURI返回’/ media / external / images / media / 11.

我想获得真正的路径,但window.resolveLocalfileSystemURL只返回’content:// media / external / images / media / 11′.

我想要得到像’/mnt/sdcard/DCIM/camera/321321321.jpg’这样的东西.

解决方法 我刚刚找到了解决方案.代码更改应该在插件中完成,而不是在JavaScript文件中.

首先找到CameraLauncher.java

添加此功能.这是将’/ media / external / images / media /’转换为realpath的功能

public String getRealPathFromURI(Uri contentUri) {    String res = null;    String[] proj = { MediaStore.Images.Media.DATA };    Cursor cursor = cordova.getActivity().getContentResolver().query(contentUri,proj,null,null);    if(cursor.movetoFirst()){;       int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);       res = cursor.getString(column_index);    }    cursor.close();    return res;}

然后找到这一行.这是在navigator.camera.getPicture上返回imageURI的那个(success())

if (this.targetHeight == -1 && this.targetWIDth == -1 &&        (destType == file_URI || destType == NATIVE_URI) && !this.correctOrIEntation) {    this.callbackContext.success(uri.toString());}

将此行更改为

if (this.targetHeight == -1 && this.targetWIDth == -1 &&        (destType == file_URI || destType == NATIVE_URI) && !this.correctOrIEntation) {    this.callbackContext.success(getRealPathFromURI(uri)); }
总结

以上是内存溢出为你收集整理的android – cordova相机插件获取所选图像的真实路径全部内容,希望文章能够帮你解决android – cordova相机插件获取所选图像的真实路径所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1141103.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存