更新时间:2021-06-30 21:46:43
我编写了一段代码来检查设备是否为奥利奥(Oreo)
I write the piece of code for checking if the device is oreo
String NOTIFICATION_CHANNEL_ID = "my_channel_id_01";
NotificationManager notificationManager1 = (NotificationManager)
getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_DEFAULT);
// Configure the notification channel.
notificationChannel.setDescription("Channel description");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
notificationChannel.enableVibration(true);
notificationManager1.createNotificationChannel(notificationChannel);
}
mNotification = builder
.setLargeIcon(image)/*Notification icon image*/
.setContentText(messageBody)
.setSmallIcon(R.drawable.dhlone)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(image).bigLargeIcon(image))/*Notification with Image*/
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setBadgeIconType(R.drawable.dhlone)
.setAutoCancel(true)
.setSmallIcon(getNotificationIcon())
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext()
.getResources(),R.drawable.dhlone))
.build();
notificationManager1.notify(/*notification id*/0, mNotification);