Notification.Builder
中的setDefaults
在Android O及以上版本(SDK >= 26)已被弃用。
同样,setSound
也是如此。
以下是我的代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
b.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_luncher_new)
.setContentTitle(Title)
.setTicker(Title)
.setContentText(Msg)
.setChannelId("cid")
.setDefaults(Notification.DEFAULT_ALL)
.setStyle(new Notification.BigTextStyle().bigText(Msg))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(contentIntent);
}
NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.createNotificationChannel(mChannel);
}
notificationManager.notify(id, b.build());`
我应该替换什么?我没有找到任何有用的例子。