2

Is there a way in Android (starting with API 8) to create a service that will listen to MediaStore updates, so on that it, will notify the app to do something with the new content.

I know how to make a Service. But I've bin looking for an example with such a listener, and found only a solution with sendBroadcast(). But I don't want every time to update (explicit) the MediaStore, just a listener that could wait for an update notification.

Is there such a possibility? (Or, may be, my question is not quite right).

Goo
  • 1,318
  • 1
  • 13
  • 31
Serj Lotutovici
  • 4,370
  • 5
  • 32
  • 41

1 Answers1

1

You could use the AlarmManager to fire a Service that will check for updates on an interval. Run something like this every time your activity starts.

AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(context, MyCheckForUpdates.class);
PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0);

mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), PERIOD, pi);