0

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


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

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

4

1 回答 1

1

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

以下是一些可能性:

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

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

  3. 您可能没有请求VIBRATE许可。

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

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

  6. 在你构建你的方式中有些东西搞砸了flags——切换到Notification.BuilderNotificationCompat.Builder可能会有所帮助。

于 2013-07-09T10:12:54.520 回答