Android 关于推送通知还需要一些其他的设置问题,2021京东最新Android面试真题解析

本文详细解析了Android系统中关于推送通知的配置,包括设置通知渠道的振动、灯光、声音等特性,并提供了针对不同Android版本的Notification构建方法。同时,文章讨论了面试中可能涉及的Android通知相关知识点,如通知权限检查和后台运行设置。
摘要由CSDN通过智能技术生成

// notificationChannel.enableVibration(true);//是否允许震动

// notificationChannel.setVibrationPattern(new long[]{100, 100, 200});//设置震动模式

// notificationChannel.getAudioAttributes();//获取系统响铃配置

// notificationChannel.getGroup();//获取消息渠道组

// notificationChannel.setBypassDnd(true);

// notificationChannel.setDescription(“description”);

// notificationChannel.setLightColor(Color.GREEN);//制定闪灯是灯光颜色

// notificationChannel.setShowBadge(true);

// getNotificationManager().createNotificationChannel(notificationChannel);

//第一个参数:channel_id

//第二个参数:channel_name

//第三个参数:设置通知重要性级别

//注意:该级别必须要在 NotificationChannel 的构造函数中指定,总共要五个级别;

//范围是从 NotificationManager.IMPORTANCE_NONE(0) ~ NotificationManager.IMPORTANCE_HIGH(4)

NotificationChannel channel = new NotificationChannel(id, name,

NotificationManager.IMPORTANCE_DEFAULT);

// channel.canBypassDnd();//是否绕过请勿打扰模式

channel.enableLights(true);//闪光灯

channel.setLockscreenVisibility(VISIBILITY_SECRET);//锁屏显示通知

channel.setLightColor(Color.RED);//闪关灯的灯光颜色

channel.canShowBadge();//桌面launcher的消息角标

channel.enableVibration(true);//是否允许震动

channel.getAudioAttributes();//获取系统通知响铃声音的配置

channel.getGroup();//获取通知取到组

channel.setBypassDnd(true);//设置可绕过 请勿打扰模式

channel.setVibrationPattern(new long[]{100, 100, 200});//设置震动模式

channel.shouldShowLights();//是否会有灯光

getNotificationManager().createNotificationChannel(channel);

}

}

/**

  • 获取通知管理者对象

  • @return

*/

public NotificationManager getNotificationManager() {

if (notificationManager == null) {

notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

}

return notificationManager;

}

/**

  • 对应Android8.0生成notification的方法,通过此方法获取notification

*/

public Notification.Builder getChannelNotification(int iconRes, Str

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值