5

Android バージョン 5.1.1 の Nexus 4 電話を使用して、Android イメージ ギャラリーから共有イメージを受信したいと考えています。phonegap 4.2 と phonegap WebIntent プラグインgithub linkと phonegap file plugin doc linkを使用しています。

テキストとリンクは正常に機能しますが、Android ギャラリーから画像を共有しようとすると、次のような URI が返されます。

content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F63131/ACTUAL

file:///... のようなものの代わりに

window.resolveLocalFileSystemURL 関数を使用して、fileEntry オブジェクトで成功を返すこの URL を解決しようとしました。ただし、それを使用してファイルを読み取ろうとすると、コード 1000 のエラーが発生します (以下のコードと出力を参照)。

興味深いことに、この URL を img タグを介して表示すると、画像が正常に表示されます。

<img src="" id="test_intent_image">
$('#test_intent_image').attr("src",uri);

これは、問題が content://... タイプ uris を適切に処理できない window.resolveLocalFileSystemURL 関数である可能性があることを示唆していますか?

=====参考情報======

これが私が使用しているコードです(注:アプリフォルダーへのcopyTo()などの他のファイル関数でこれを試しましたが、同じエラーが発生します):

    document.addEventListener("deviceready", shared, false);
    document.addEventListener("resume", shared, false);


 function shared () {

window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_STREAM,
function(data) {
// data is the value of EXTRA_TEXT
    if (! data) {
        return;
    }

    window.resolveLocalFileSystemURL(
        data, 
        function (entry) {
            console.log('file entry: ' + JSON.stringify(entry, null,3) );

            function win(file) {
                var reader = new FileReader();
                reader.onloadend = function (evt) {
                    console.log("file read success");
                    console.log(evt.target.result);
                };

                reader.readAsText(file);
            };

            function fail (error) {
                console.log("file read error: " + error.code);
            };

            entry.file(win, fail);

        }, 
        function (error) {
            console.log('file error: ' + error);
        });

}, function() {
    // There was no extra supplied.
    // debug_log("web intent getExtra: no extra");
    }
);

}

画像ギャラリーから画像を共有しようとしたときのコードのコンソール出力は次のとおりです。

handle share stream :"content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F63087/ACTUAL"
file entry: {
   "isFile": true,
   "isDirectory": false,
   "name": "ACTUAL",
   "fullPath": "/com.google.android.apps.photos.contentprovider/0/1/content%3A//media/external/images/media/63087/ACTUAL",
   "filesystem": "<FileSystem: content>",
   "nativeURL": "content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F63087/ACTUAL"
}
file read error: 1000

AndroidManifest.xml ファイルのインテント フィルターを次に示します。注: 共有は正常に機能しますが、URL を解決できないため、おそらく問題にはなりません。

<intent-filter>
<action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>
4

2 に答える 2