0

i have a problem with the the downloaded files in my PhoneGap-App for Android. The download-Function from PhoneGap actually works quite well i think. It gets the file from the URL and stores it on the SD-Card. (Code is below)

So where is the Problem? When I download a JPG or PNG to the Download-folder, i want it be accessible through the native Gallery. But the picture don´t appear in the gallerie. To see it I have to restart the phone or I have to use another App like Astro.

Is there a "Refresh_the_native_Gallerie"-Function or something like that?

Thank you very much.

try {
     var filePath = 'file:///mnt/sdcard/Download/google.png'; // Correct filePath
     var url = "https://www.google.de/images/srpr/logo3w.png"; //Correct URL

     var fileTransfer = new FileTransfer();

     fileTransfer.download(url, filePath, function(entry) {
         console.log("s3_download download complete: " + entry.
         // Do i need a "Refresh_all_other_Apps"-function here?
     }, function(error) {
     // Normally no Error
         console.log("s3_download download error source " + error.source);
         console.log("s3_download download error target " + error.target);
         console.log("s3_download download error code" + error.code);
     });
} catch (e) {
     console.log("downloadTest ERROR: " + e);
}

Cannot answer my own question so fast only edit my question. So here is the answer:

I wrote a little PhoneGap-Plugin, which does actually nothing more than calling the code from zapl. Thanks again. Hope it will help someone with the same problem.

You can find the code here: https://github.com/philipp-at-greenqloud/pluginRefreshMedia

4

3 に答える 3

5

それがPhoneGap / JavaScriptのコンテキストで役立つかどうかはわかりません:

問題は、デバイスのメディア データベースでインデックスが作成されたファイルのみがギャラリーに表示されることです。ファイル システムにファイルを追加するだけでは、そのファイルがそのデータベースに自動的に追加されるわけではありません。そして、そのデータベースの再スキャン/更新が行われるのは、デバイスを再起動するか、SDカードを再マウントするときだけです(PCと共有した後、または取り出して元に戻した場合)。

ファイルをデータベースに追加する最も簡単な方法は、Intent#ACTION_MEDIA_SCANNER_SCAN_FILEを MediaScanner に送信して、ファイルをデータベースに追加できるようにすることです。それが完了すると、ファイルがギャラリーに表示されます。

そのためのJavaコードは次のようになります

File newImage = new File("/mnt/sdcard/Download/google.png");
Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
scanIntent.setData(Uri.fromFile(newImage));
sendBroadcast(scanIntent);
于 2012-08-14T15:07:55.213 に答える
0

これは非常に必要なプラグインです。私はこの問題の回避策を試みてきましたが、プラグインはうまく機能します。私は自分で開発することを検討していましたが、あなたは素晴らしい仕事をしました。頭痛は今は治まっています。これは私にとってはうまくいきます。

于 2012-08-27T12:34:37.283 に答える
0

私は小さな PhoneGap-Plugin を書きましたが、実際には zapl からコードを呼び出すだけです。再度、感謝します。同じ問題を抱えている人に役立つことを願っています。

ここでコードを見つけることができます: https://github.com/philipp-at-greenqloud/pluginRefreshMedia

于 2012-08-16T09:47:59.837 に答える