我有一个帮助程序类,可以帮助我构建和显示一个包含2个状态的通知。
在构造函数中,我正在使用两种状态的常用设置初始化NotificationCompat.Builder
。然后在一个方法(showNotificationCircle()
)中,我显示带圆圈图标,一些文字和“点击”声音的通知。
在另一种方法(showNotificationRect()
)中,我正在显示另一个图标,一些文本和另一种声音的通知,但是当通知出现时,无论使用何种方法,它仍然是相同的声音。
这是我的构造函数:
public NotifHelper(Context context) {
clickSoundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.click_sound);
bulbSoundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.bulb_sound);
builder = new NotificationCompat.Builder(context);
builder.setContentTitle(context.getString(R.string.some_text_1))
.setColor(context.getResources().getColor(R.color.white))
.setAutoCancel(false)
.setShowWhen(false)
.setOngoing(true)
.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
}
这是我的圈状态方法:
public void showNotificationCircle() {
builder.setContentIntent(pendingIntent);
builder.setSmallIcon(R.mipmap.ic_circle);
builder.setPriority(Notification.PRIORITY_DEFAULT);
builder.setSound(clickSoundUri);
notification = builder.build();
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(NOTIFICATION_ID, notification);
}
第二种方法:
public void showNotificationRect() {
builder.setContentIntent(pendinIntent2);
builder.setSmallIcon(R.mipmap.ic_rect);
builder.setPriority(Notification.PRIORITY_MIN);
builder.setSound(bulbSoundUri);
notification = builder.build();
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(NOTIFICATION_ID, notification);
}
我不知道为什么在调用showNotificationRect()
时播放只是'clickSoundUri'而不是'bulbSoundUri'。