Commit 790fdab4 by zhangchengbo

fix:取消通知栏-自定义消息推送,采用系统自带消息推送。(解决推送消息重复展示2条)

parent f41ba949
...@@ -3,6 +3,7 @@ package com.secspace.sms.services ...@@ -3,6 +3,7 @@ package com.secspace.sms.services
import android.app.Notification import android.app.Notification
import android.app.NotificationChannel import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.content.Context
import android.os.Build import android.os.Build
import android.service.notification.NotificationListenerService import android.service.notification.NotificationListenerService
import android.service.notification.StatusBarNotification import android.service.notification.StatusBarNotification
...@@ -28,18 +29,14 @@ class SmsNotificationListener : NotificationListenerService() { ...@@ -28,18 +29,14 @@ class SmsNotificationListener : NotificationListenerService() {
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.O)
override fun onNotificationPosted(sbn: StatusBarNotification) { override fun onNotificationPosted(sbn: StatusBarNotification) {
super.onNotificationPosted(sbn) super.onNotificationPosted(sbn)
if(isShowNotification) return /* if(isShowNotification) return
// 可见的通知中存在系统发出的关于顶层包名的通知时,取消显示 // 可见的通知中存在系统发出的关于顶层包名的通知时,取消显示
val notification: Notification? = sbn.notification val notification: Notification? = sbn.notification
// if (notification?.publicVersion == null) return // publicVersion 获取为null 1.有可能该通知没有公共版本 2.浏览器不支持或实现有限 3.未满足权限或场景要求 // if (notification?.publicVersion == null) return // publicVersion 获取为null 1.有可能该通知没有公共版本 2.浏览器不支持或实现有限 3.未满足权限或场景要求
// 检查通知是否来自短信应用
try { try {
val packageName = sbn.packageName val packageName = sbn.packageName
Log.d(TAG, "SmsNotificationListener 短信通知:packageName=$packageName") Log.d(TAG, "SmsNotificationListener 短信通知:packageName=$packageName")
if (isSmsPackage(packageName)) { if (isSmsPackage(packageName)) {
//移出系统通知栏消息
// cancelNotification(sbn.key)
// 获取通知内容 // 获取通知内容
val title = getTitle(notification) val title = getTitle(notification)
val content = getContent(notification) val content = getContent(notification)
...@@ -95,7 +92,7 @@ class SmsNotificationListener : NotificationListenerService() { ...@@ -95,7 +92,7 @@ class SmsNotificationListener : NotificationListenerService() {
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "NotificationListener e: ${e.localizedMessage}") Log.e(TAG, "NotificationListener e: ${e.localizedMessage}")
cancelAllNotifications() cancelAllNotifications()
} }*/
} }
override fun onNotificationRemoved(sbn: StatusBarNotification?) { override fun onNotificationRemoved(sbn: StatusBarNotification?) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment