0


As you can see, I'm new here (but not new to programming). I'm working on my first android camera app, and I cant get my video files to show up in the gallery. I understand that I need to inform the system of my new file's Content Values, but nothing I try is working.

Strangely this works just fine for images:

ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, imgFile.getAbsolutePath());
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);


Yet this does not always make videos visible in the gallery app:

ContentValues values = new ContentValues();
values.put(MediaStore.Video.Media.DATA, vidFile.getAbsolutePath());
getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);

I assure you it is a valid video file, and sometimes the above code works. I cannot find a pattern for when it will work and when not, though.
I have also tried a few other variations to getContentResolver().insert. In fact, If I tell it my video file is an image, it always updates the gallery with a nonviewable image that is my video.
Thanks much in advance for any help!

Trihedral
  • 1
  • 2

1 Answers1

0

Well this has been an ordeal, but I found a work-around. Actually this new solution might be better then what I was trying to do. Depends on the overheads of the various methods I suppose.

As stated by Pascal here, I can update the content provider by broadcasting the proper intent:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(imageAddedOrDeleted)));

This makes my videos visible to my gallery app every time (thank god, I was about to resort to writing my own built in viewer) But I'm still curious why my method works for images but not video, in case anyone knows.

Community
  • 1
  • 1
Trihedral
  • 1
  • 2