Cannot find file in the gallerie after downloading it with PhoneGap in Android

后端 未结 3 1497
夕颜
夕颜 2021-01-16 18:03

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 t

相关标签:
3条回答
  • 2021-01-16 18:32

    I don't know if that helps you in PhoneGap / JavaScript context:

    Your problem is that the gallery will only display files that are indexed in the device media-database. Just adding a file to the file system will not automatically add it to that database. And pretty much the only time a rescan / update of that database happens is when you reboot the device or remount the sdcard (after it was shared with a PC or in case you ejected it and put it back in).

    To have a file added to the database the simplest way to to that is to send Intent#ACTION_MEDIA_SCANNER_SCAN_FILE to the MediaScanner to let it add your file to the database. Once that is done the file will show up in the gallery.

    Java code for that would be

    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);
    
    0 讨论(0)
  • 2021-01-16 18:40

    This is a well needed plugin. I have been trying to do work arounds for this issue and the plugin works a treat. I was looking at developing one myself, but you have done a great job. My headaches are now subsiding. This works for me.

    0 讨论(0)
  • 2021-01-16 18:48

    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

    0 讨论(0)
提交回复
热议问题