无法从画廊的Andr​​oid访问图像时

无法从画廊的Andr​​oid访问图像时

本文介绍了无法从画廊的Andr​​oid访问图像时,设置图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

荫使用科尔多瓦3.4。当我拍摄图像,并设置它,它工作正常,但是当我尝试从画廊图像访问我得到的网址

Iam using cordova 3.4. When i capture an image and set it,its working fine but when I try to access on image from gallery I get the url

content://com.android.providers.media.documents/document/image%4A463

和我在我的形象tag.I知道这一点得到图像加载错误是知道错误绕来绕去,我已经refered栈的问题,如Unable使用从图库中选择在Android 4.4(奇巧)时加载图像PhoneGap的摄像头插件

and I get image load error in my image tag.I know this is a know bug going around and I have refered stack questions such as Unable to load image when selected from the gallery on Android 4.4 (KitKat) using PhoneGap Camera Plugin

我不能用身边提到的做工粗糙,其中的URI手动设置,如内容://媒体/外部/图片/媒体/因为我们专注内置存储,如摩托罗拉内部设备

I cannot use the rough work around mentioned where URI is set manually like content://media/external/images/media/ because we focus devices with internal built in storage such as Moto

也可以请你确认此问题已得到修复科尔多瓦3.5.Because我需要获得许可从我的官员进行下载,我必须确保它是可以实现的。可以请人帮忙

Also can you please confirm that this issue has been fixed in cordova 3.5.Because I require permission from my officials for download and I must make sure it is achievable .Can somebody please help

更新:

app.directive('upload', function() {
return {
    restrict: 'A',
    require: 'ngModel',
    link: function(scope, elm, attrs, ctrl) {
        elm.on('click', function() {
            navigator.camera.getPicture(
                    function(imageURI) {
                        scope.$apply(function() {
                            alert(imageURI);
                               ctrl.$setViewValue(imageURI);
                        });
                        window.resolveLocalFileSystemURI(imageURI, function(fileEntry)                                                                       {
                             //                                                   ctrl.$setViewValue(imageURI);
                            alert("inside local file" + imageURI);
                            alert("Inside local file system");
                            fileEntry.file(function(fileObj) {
                                alert("hai");
                                var options = new FileUploadOptions();
                                options.fileKey = "file";
                                options.fileName = fileObj.name;
                                options.mimeType = fileObj.type;
                                var ft = new FileTransfer();
                                // var url = fileUploadUrl;
                                // ft.upload(imageUri, encodeURI(url), success,                 failure, options);
                            });
                        });
                    },
                    function(err) {
                        ctrl.$setValidity('error', false);
                    }, {quality: 50,
                destinationType: Camera.DestinationType.FILE_URI,
                  sourceType: Camera.PictureSourceType.PHOTOLIBRARY
            }
            );
        });
    }
};
       });

我的HTML:

My HTML:

  <img
                    ng-src="{{onepic}}"
                    width="250"
                    height="390"
                    alt="error"/>

我设定值onepic在我的手表function.So内部控制指令时,返回一个URI将在onepic.Please自动设置指定任何替代解决方案,或者荫做错什么,荫新angularjs

I set value for onepic in my controller inside watch function.So when directive returns a URI it will be automatically set in onepic.Please specify any alternative solution or if Iam doing anything wrong ,Iam new to angularjs

推荐答案

试试这个..

在摄像头插件有一个 FileHelper.java 文件,替换插件 getRealPath 我的这种我的方法。

In Camera Plugin there is one FileHelper.java File, Replace the plugin getRealPath with my this my method.

有关详细信息,你可以按照这个 - > https://issues.apache.org / JIRA /浏览/ CB-5398

For more details you can follow this -> https://issues.apache.org/jira/browse/CB-5398

FileHelper.java

FileHelper.java

    @SuppressWarnings("deprecation")
    public static String getRealPath(String uriString, CordovaInterface cordova) {
        String realPath = null;


        final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

        // DocumentProvider
        if (isKitKat) {
        Cursor cursor =  cordova.getActivity().getContentResolver().query(Uri.parse(uriString), null, null, null, null);
        cursor.moveToFirst();
        String document_id = cursor.getString(0);
        document_id = document_id.substring(document_id.lastIndexOf(":")+1);
        cursor.close();

        cursor = cordova.getActivity().getContentResolver().query(
        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
        null, MediaStore.Images.Media._ID + " = ? ", new String[]{document_id}, null);
        cursor.moveToFirst();
        String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
        realPath = path;
        cursor.close();
        }else{

        if (uriString.startsWith("content://")) {
            String[] proj = { _DATA };
            Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(_DATA);
            cursor.moveToFirst();
            realPath = cursor.getString(column_index);
            if (realPath == null) {
                LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
            }
        } else if (uriString.startsWith("file://")) {
            realPath = uriString.substring(7);
            if (realPath.startsWith("/android_asset/")) {
                LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
                realPath = null;
            }
        } else {
            realPath = uriString;
        }

        }
        return realPath;
    }

CameraLauncher.java 类therer是一种方法 processResultFromGallery

In CameraLauncher.java Class therer is one method processResultFromGallery

private void processResultFromGallery

查找此code:

Find this code:

    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) {

            String s    =FileHelper.getRealPath(uri.toString(), cordova);
            Log.i("test","<<<<ifURI::::::"+s +"URI::::" + uri.toString());
            this.callbackContext.success(s);

     }

这篇关于无法从画廊的Andr​​oid访问图像时,设置图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 16:41