【问题标题】:Android Notification Vibration/LED doesn't work?Android 通知振动/LED 不起作用?
【发布时间】:2011-05-04 23:52:33
【问题描述】:

您好,我查看了有关通知的文档,但没有任何帮助。我遵循了建议并将其应用于以下课程:(已评论问题) 我想应用伴随状态栏通知的振动和/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; 

【问题讨论】:

    标签: android


    【解决方案1】:

    您具体在哪里定义通知?您的 Notification 实例是 note 对象,因此未定义通知。

    要解决您的问题,只需将所有通知引用替换为注释即可。

    【讨论】:

    • 您好,我将它们全部替换为测试笔记。当我运行应用程序时,没有出现任何通知。
    • 您是否检查过通知是否正确传递给了 NotificationManager?
    • 顺便说一句,Notification 构造函数已被弃用,您应该使用 Notification.Builder:Notification API Reference
    • 谢谢!我要试试这个。非常感谢。
    • 谢谢!只是状态栏通知起作用了,只是当我尝试添加振动和LED灯功能时才会出现问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2022-11-06
    相关资源
    最近更新 更多