【发布时间】:2017-05-08 07:45:45
【问题描述】:
我目前正在开发一个应用程序,它的通知系统运行良好。除非我从 firebase 向手机发送消息,否则通知不会发出声音(默认手机声音)。问题是我的 java 程序出了什么问题。
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, page1.class);//**The activity that you want to open when the notification is clicked
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
【问题讨论】:
标签: java android firebase push-notification ringtonemanager