【发布时间】:2021-06-18 11:26:11
【问题描述】:
我正在尝试为 android 实现通知。我可以触发通知,但手机没有收到通知振动。这是示例代码。
String CHANNEL_ID = "Channel1";
inboxStyle.addLine("Alex Faarborg Check this out");
inboxStyle.setBigContentTitle(messagesCount + " new messages");
inboxStyle.setSummaryText("Chat room");
Notification summaryNotification =
new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
.setContentTitle("Chatroom has new messages")
.setContentText(messagesCount+" new messages")
.setSmallIcon(R.drawable.ic_launcher_background)
.setStyle(inboxStyle)
.setGroupSummary(true)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_ID, NotificationManager.IMPORTANCE_DEFAULT);
channel.enableVibration(true);
channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
notificationManager.createNotificationChannel(channel);
notificationManager.notify(SUMMARY_ID, summaryNotification);
【问题讨论】:
-
确保您的手机没有处于静音状态
-
尝试卸载应用并重新安装。
-
@Ctrl_see ,感谢您的建议。它现在正在工作。
-
很高兴我能帮上忙。
-
@SamChen,谢谢,当我卸载并重新安装该应用程序时它正在工作。
标签: android android-notifications