2
嗨我看過有關通知的文檔,但它沒有幫助。我遵循了這個建議並將它應用到了下面的課程中:(該問題已被評論) 我想在狀態欄通知(狀態欄通知確實有效)的同時應用振動和/ LED。當我按照文檔建議,它聲明我必須插入:otification.defaults | = Notification.DEFAULT_VIBRATE;但是我收到一個錯誤,說通知無法解析爲變量,如果我將「通知」更改爲note.notification,我根本沒有收到任何通知。該應用程序只運行如果我刪除了我爲你評論的行。我不確定我哪裏出錯了?謝謝。Android通知振動/ LED不起作用?
公共類ReminderService擴展WakeReminderIntentService {
public ReminderService() {
super("ReminderService");
}
@Override
void doReminderWork(Intent intent) {
Log.d("ReminderService", "Doing work.");
Long rowId = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID);
NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(this, ReminderEditActivity.class);
notificationIntent.putExtra(RemindersDbAdapter.KEY_ROWID, rowId);
PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
Notification note=new Notification(android.R.drawable.stat_sys_warning, getString(R.string.notify_new_task_message), System.currentTimeMillis());
note.setLatestEventInfo(this, getString(R.string.notify_new_task_title), getString(R.string.notify_new_task_message), pi);
note.defaults |= Notification.DEFAULT_SOUND;
//這是我遇到的問題
**notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;**
note.flags |= Notification.FLAG_AUTO_CANCEL;
嗨我用一個便箋替換它們全部進行測試。當我運行應用程序時,沒有任何通知出現。 – Superunknown 2011-05-04 15:54:23
您是否檢查過您是否將通知正確傳遞給了NotificationManager? – Moystard 2011-05-04 16:00:05
順便說一句,Notification構造函數已被棄用,您應該使用Notification.Builder:[Notification API Reference](http://developer.android.com/reference/android/app/Notification.html) – Moystard 2011-05-04 16:02:31