我的目標是有一個簡單的程序,每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