android 环信8.0通知栏,Android 8.0 通知栏适配

8.0新增了一个NotificationChannel这个特性,在target >=26的情况下,会发现无法展示通知。

解决方案

public void showNotification(){

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

String channelId = "chat";

String channelName = "chat message";

int importance = NotificationManager.IMPORTANCE_HIGH;

createNotificationChannel(channelId, channelName, importance);

}

Notification notification = new NotificationCompat.Builder(this, "chat")

.setContentTitle(title)

.setContentText(body)

.setCategory(NotificationCompat.CATEGORY_MESSAGE)

.setFullScreenIntent(null, true)

.setContentIntent(pendingIntentClick)

.setWhen(System.currentTimeMillis())

.setVisibility(Notification.VISIBILITY_PUBLIC)

.setSmallIcon(R.drawable.ic_launcher)

.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))

.setAutoCancel(true)

.build();

}

@RequiresApi(api = Build.VERSION_CODES.O)

private void createNotificationChannel(String channelId, String channelName, int importance) {

NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);

NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

manager.createNotificationChannel(channel);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值