通知不会振动或显示灯光

时间:2013-07-09 10:06:24

标签: android notifications vibrate

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


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"/>

然而,这不会振动或显示灯光。有谁知道为什么这不起作用?

1 个答案:

答案 0 :(得分:1)

  

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

以下是一些可能性:

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

  2. 您的设备可能没有振动电机。

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

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

  5. 此设备的默认振动模式为“无”,即使它有振动电机。

  6. 您构建flags的方式有些混乱 - 切换到Notification.BuilderNotificationCompat.Builder可能会有所帮助。