对于我正在开发的应用程序,我想向用户发送一个非常注重要求的通知。为此,我有以下代码:
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"/>
然而,这不会振动或显示灯光。有谁知道为什么这不起作用?
答案 0 :(得分:1)
有人知道为什么这不起作用吗?
以下是一些可能性:
您的设备可能不会使用LED进行通知。
您的设备可能没有振动电机。
您可能没有请求VIBRATE
权限。
此设备的默认灯光为“无”,即使设备能够使用LED进行通知。
此设备的默认振动模式为“无”,即使它有振动电机。
您构建flags
的方式有些混乱 - 切换到Notification.Builder
或NotificationCompat.Builder
可能会有所帮助。