Background
When the user downloads a new image or captures one using the camera, the gallery app will get updated to show the new images.
I need to be notified of each new image as soon as it was created, no matter how it was created (camera, browser,...) , just as the gallery app shows.
The problem
As it turns out there is a mediaScanner Android component that is responsible for scanning all types of media files, and when it finishes, it's supposed to send an intent "MEDIA_SCANNER_FINISHED" (as shown on this example) .
So I've added the next code , hoping it will show a toast each time the user takes a photo from the camera app:
manifest:
...
<receiver android:name="com.example.newgalleryimagereceivertest.MediaScannerBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_SCANNER_FINISHED" />
<data android:scheme="file" />
</intent-filter>
</receiver>
...
java file:
package com.example.newgalleryimagereceivertest;
...
public class MediaScannerBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
android.util.Log.d("AppLog", "gallery has new images");
}
For some reason , this code doesn't work ...
The question
What's wrong with the code?
Will the broadcastReceiver ever be called after taking a photo?
What is the correct way to do it?
Do I really need to use a contentObserver and monitor its changes (using something like this), and keep the app running just for this? I really hope not...