質問

Cordova 3.4を用いた

IAM。私がイメージをキャプチャしてそれを設定したとき、それをうまくいくがギャラリーから画像にアクセスしようとしたとき、私はURLを取得します

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

そして私のイメージのロードエラーを取得します。私はこれが周りの知識のバグであることを知っています、そして私は PhoneGap Camera Pluginを使用してAndroid 4.4(Kitkat)のギャラリーから選択したときにイメージをロードできません。 a>

私は述べたように概要を回避することはできませんURIが手動でコンテンツのように設定されている場合:// media / external / images / media / Moto

などの内蔵ストレージに集中するため

また、この問題がCordova 3.5で修正されたことを確認できます。私はダウンロードのために私の職員から許可を必要としています、そして私はそれが達成可能であることを確認しなければならない。誰かが助けを助けてください

更新:

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:

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

私のコントローラ内のOnePicの値を設定します。watch functionsのwatch functions.so oneピックで自動的に設定されます。代替ソリューションを指定してください。

役に立ちましたか?

解決

これを試してみてください..

カメラプラグインのFileHelper.javaファイルが1つあり、Plugin getRealPathをこのマイメソッドに置き換えます。

詳細については、次のとおりです。/ JIRA / BROWSE / CB-5398

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クラスはそれが1つのメソッドprocessResultFromGallery

です。
private void processResultFromGallery
.

このコードを探す:

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

     }  
.

他のヒント

これ回答:

    if (imageUri.toString().substring(0,21).equals("content://com.android")) {
          String [] photo_split= imageUri.toString().split("%3A");
          String imageUriBasePath = "content://media/external/images/media/"+photo_split[1];
           imageUri= Uri.parse(imageUriBasePath );

        }
.

uri<img src="uri" />に渡されるたび、

から暗黙的にデコードされている

コンテンツ://com.android.providers.media.documents/Document/Image%3A9888 (1)

コンテンツ://com.android.providers.media.documents/Document/Image:9888 (2)

しかし、Intent.ACTION_OPEN_DOCUMENTまたはIntent.ACTION_GET_CONTENTから戻った後、(2)ではなく、(1)の読み取り権限を提供します。この場合、WebViewはエラーを記録します:

java.lang.securityException:許可拒否:読み取り com.android.providers.media.MediaDocumentsProvider Uri. コンテンツ://com.android.providers.media.documents/Document/Image:9888 PID= 13163から、UID= 10165が必要です Android.permission.manage_documents、またはtranguripersivision()

または

コンテンツURLを開くことができません

コードスニペット

問題を解決する必要があるのは

    String uriToUseInWebView = transformForWebView(uri.toString());

    private String transformForWebView(String uri) {
        for (int i = 0; i < timesDecodingWebView(); i++)
            uri = uri.replace("%", Uri.encode("%"));
        return uri;
    }

    private int timesDecodingWebView() {
        if (Build.VERSION.RELEASE.equals("4.4.2")) {
            return 2;
        } else {
            return 1;
        }
    }
.

Javaコードでは、(1)が実際にロードされるようにするためにHTML / JSに渡す前にJavaコードで。

4.4.2,4.4.4、5.0でテストしました。面白い部分は、Android 4.4.2がuriを内部的に2回デコードすることです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top