我的目标是有一个简单的程序,每X秒获取一次图像URL的内容,将其写入/ media/screensavers/Messages目录,然后解锁并重新锁定设备(Nook Simple Touch),以便显示新下载的图像。Android解锁屏幕,然后重新锁定屏幕(Nook简单触摸)
当它应该和图像下载时(我可以通过Android Studio logcat看到),警报会熄灭。问题是角落没有解锁。 (屏幕不更新)。
这里是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?
}
我的代码,我试图从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);
但getWindow()
这个代码是RED(无法解析法)。
我试过使用context.getWindow()
,但也有错误。如何从onReceiver上下文访问getWindow?
目标:通过
- 下载图片(完成)
- 写入图像目录(完成)
- 解锁装置
- 锁定devive
刷新 '屏幕保护程序' 的形象谢谢!
'AlarmReceiver'没有这样的方法,你需要实现活动并启动它。 – gio 2014-12-27 20:14:21