我開發了一個應用程序,我需要一個廣播接收器來生成有關從GCM推送接收消息的通知 。廣播接收器中的WakeLock採集問題
我使用的代碼拒絕編譯,指出
"Cannot make a static reference to the non-static method acquire() from
the type PowerManager.Wakelock"
的IDE(日食)現在建議我應該
remove argument to match "acquire()"
然而,當我這樣做,顯示下一個錯誤是:
The method acquire(long) in the type PowerManager.WakeLock is not applicable
for the arguements(Context)....
用於廣播接收器中的代碼是:
private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
WakeLock.acquire(getApplicationContext());
// Showing received message
lblMessage.append(newMessage + "\n");
Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG).show();
// Releasing wake lock
WakeLock.release();
}
我在哪裏錯過了?
您正在試圖調用對象(非靜態)方法類(靜態)方法添加的權限。 – piotrpo 2013-03-03 08:49:17