object NotificationUtil {
//程序通知设置是否开启
fun notificationEnabled(context: Context): Boolean {
return NotificationManagerCompat.from(context).areNotificationsEnabled()
}
//程序指定通知渠道设置是否开启
fun channelEnabled(context: Context, channelId: String): Boolean {
var enabled = true
val notificationChannel =
NotificationManagerCompat.from(context).getNotificationChannel(channelId)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
enabled = notificationChannel?.importance != NotificationManagerCompat.IMPORTANCE_NONE
}
return enabled
}
//跳转到程序通知设置界面
fun openNotificationSetting(context: Context) {
val intent = Intent()
when {
Build.VERSION.SDK_INT >= 26 -> {
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
intent.putExtra(Settings.EXTRA_APP_PACKAGE, c
Android应用通知功能封装
最新推荐文章于 2023-11-09 17:34:27 发布