我有一个4单选按钮通知类型0,1,2,3如果用户选择通知类型0,用户不应该得到通知。如何按程序进行。
(notificationType != 0) {
if (notificationType == 1) {
soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
if (notificationType == 2) {
soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.azan);
}
if (notificationType == 3) {
soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.mohsin_mava);
}
}
NotificationReceiver.java文件
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel mChannelFajr = notificationManager.getNotificationChannel(FAJR_CHANNEL_ID);
if (mChannelFajr == null) {
mChannelFajr = new NotificationChannel(FAJR_CHANNEL_ID, fajrChannelName, importance);
mChannelFajr.setDescription(notificationText);
mChannelFajr.enableVibration(true);
mChannelFajr.enableLights(true);
mChannelFajr.setLockscreenVisibility(VISIBILITY_PUBLIC);
mChannelFajr.setSound(soundUri, audioAttributes);
notificationManager.createNotificationChannel(mChannelFajr);
}
builder = new NotificationCompat.Builder(context, FAJR_CHANNEL_ID);
builder.setContentTitle("FAJR NAMAZ") // required
.setSmallIcon(R.mipmap.ic_darshika_logo) // required
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_darshika_logo))
.setContentText(notificationText) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setLights(Color.MAGENTA, 500, 500)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSound(soundUri)
.setContentIntent(pendingIntent)
.setTicker(context.getString(R.string.app_name));
} else {
builder = new NotificationCompat.Builder(context, FAJR_CHANNEL_ID);
builder.setContentTitle("FAJR NAMAZ")
.setSmallIcon(R.mipmap.ic_darshika_logo) // required
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_darshika_logo))
.setContentText(notificationText) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setSound(soundUri)
.setLights(Color.MAGENTA, 500, 500)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent)
.setTicker(context.getString(R.string.app_name))
.setPriority(Notification.PRIORITY_HIGH);
}
notification = builder.build();
notificationManager.notify(0, notification);
在这里,我已经为通知如何关闭它编程通道?
1条答案
按热度按时间k97glaaz1#
NotificationReceiver.java文件