【问题标题】:Notification doesn't vibrate or show lights通知不振动或不亮
【发布时间】:2013-07-09 10:06:24
【问题描述】:

对于我正在开发的应用程序,我想向用户发送一个非常需要注意的通知。为此,我有以下代码:


public void showNotification() {
    // Show a notification in the notification bar
    Notification notification = new Notification(R.drawable.ic_launcher, "Notification", System.currentTimeMillis());
    notification.flags = Notification.PRIORITY_MAX | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.FLAG_INSISTENT | Notification.DEFAULT_LIGHTS;

    Intent notificationIntent = new Intent(this, MainActivity.class);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(this, "Title", "Text", contentIntent);

    mNotificationManager.notify(R.string.app_name, notification);
}

在清单中:

<uses-permission android:name="android.permission.VIBRATE"/>

但是,这不会振动或显示灯光。有人知道为什么这不起作用吗?

【问题讨论】:

    标签: android notifications vibration


    【解决方案1】:

    有人知道为什么这不起作用吗?

    这里有一些可能性:

    1. 您的设备可能不使用 LED 进行通知。

    2. 您的设备可能没有振动马达。

    3. 您可能没有请求VIBRATE 权限。

    4. 此设备的默认灯是“无”,即使该设备能够使用 LED 进行通知。

    5. 此设备的默认振动模式是“无”,即使它有振动马达。

    6. 您构建 flags 的方式出现问题 - 切换到 Notification.BuilderNotificationCompat.Builder 可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 2022-11-06
      • 1970-01-01
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多