2011-05-04 81 views
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; 

回答

0

确切位置在哪里,你定义通知?您的通知实例是注释对象,因此未定义通知。

要解决您的问题,只需将所有通知参考替换为备注。

+0

嗨我用一个便笺替换它们全部进行测试。当我运行应用程序时,没有任何通知出现。 – Superunknown 2011-05-04 15:54:23

+0

您是否检查过您是否将通知正确传递给了NotificationManager? – Moystard 2011-05-04 16:00:05

+0

顺便说一句,Notification构造函数已被弃用,您应该使用Notification.Builder:[Notification API Reference](http://developer.android.com/reference/android/app/Notification.html) – Moystard 2011-05-04 16:02:31