您好我查看了有关通知的文档,但它没有任何帮助。我按照建议将其应用到以下类:(问题已注释) 我想在状态栏通知的同时应用振动和/ LED(状态栏通知确实有效)。当我按照文档建议时,它说明我必须插入:otification.defaults | = Notification.DEFAULT_VIBRATE;但我得到一个错误,说通知无法解析为变量,如果我将“通知”更改为note.notification,我根本不会收到任何通知。应用程序仅运行如果我删除了我为您评论过的行。我不知道我哪里出错了?感谢。
公共类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)
您在何处定义通知?您的通知实例是注释对象,因此通知未定义。
要解决您的问题,只需将所有通知引用替换为note。