My goal is to have a simple program which fetches the contents of an image URL every X seconds, writes it to the /media/screensavers/Messages directory, then unlocks and relocks the device (Nook Simple Touch) so the new downloaded img is displayed.
The alarm fires off when it should and the image downloads (I can see via Android Studio logcat). The problem is the nook does not unlock. (the screen does not update).
Here is my code from AlarmReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
// Log to logcat
Log.i("AlarmReceiver", "onReceive() -- onReceive fired! ");
// Create the dummy image url
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
String imgPath = new String();
imgPath = "http://dummyimage.com/600x800/fff/000.jpg&text=" + currentDateTimeString ;
imgPath = imgPath.replaceAll(" ", "+");
// Download and save the image (works great)
new DownloadImageTask().execute(imgPath);
// Now how do I a) unlock the device, then b) put it back to sleep?
}
I tried this code from How to programmatically dismiss the screensaver/lock screen on Android (Nook Simple Touch)
Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
but getWindow()
is RED (Can't resolve method).
I've tried using context.getWindow()
, but that also has errors. How do I access getWindow from within the onReceiver context?
Goal: Refresh the 'Screensaver' image via
- Download Image (done)
- Write image to directory (done)
- Unlock device
- Lock devive
Thanks!