MediaDroid now cycles images from the selected album
Using a Service and ACTION_SCREEN_OFF I’ve successfully added a new feature to MediaDroid which cycles the images in your photo album. Every time the screen is put to sleep, the next photo in the album is placed in the photo widget on the Home screen of your Android device. Here’s a code snippet…
public class ChangeImageService extends Service
{
private static final boolean LOGD = Constants.LOGD;
private BroadcastReceiver _receiver;
private static final String LOG_TAG = "ChangeImageService";
@Override
public void onCreate()
{
super.onCreate();
_receiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
loadNextImage();
}
};
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(_receiver, filter);
}
....
}
A couple of gotchas you have to watch out for… The ACTION_SCREEN_OFF Intent does not get picked up from the AndroidManifest.xml file so you have to assign it in code as shown above. Also, I put the assignment in the onCreate method because the Service can get killed off. If the Service is killed off, Android will schedule it to restart, but in order to catch the Screen Off broadcasts the Service must sign up again in the onCreate method…at least, this is what worked for me and all seems to be going well. As always, the docs are a little sparse and I had to go through some trial and error to figure it out, but I’m pretty happy with the results.
The new feature (along with a bug fix) is available in both the Trial and Full version of MediaDroid in the Android market…check em out and let me know what you think!
