Commit fdb07b69 by zhangchengbo

fix:添加PopWindow短信推送悬浮窗与通知栏推送展示(通讯录如果有备注则优先展示备注,其次手机号)

parent 2238abd0
...@@ -74,14 +74,12 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -74,14 +74,12 @@ class SmsReceiver : BroadcastReceiver() {
if (exists) { if (exists) {
handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status, phoneNumberResult) { handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status, phoneNumberResult) {
badgeTotalNumber(context) badgeTotalNumber(context)
// sendNotification(phoneNumberResult, body)
} }
} }
} }
} else { } else {
handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status, phoneNumberResult) { handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status, phoneNumberResult) {
badgeTotalNumber(context) badgeTotalNumber(context)
// sendNotification(phoneNumberResult, body)
} }
} }
} }
...@@ -117,7 +115,7 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -117,7 +115,7 @@ class SmsReceiver : BroadcastReceiver() {
Log.d(TAG, "SmsReceiver 短信内容相等 = ${it.threadId == threadId && it.isSFNumber }") Log.d(TAG, "SmsReceiver 短信内容相等 = ${it.threadId == threadId && it.isSFNumber }")
it.threadId == threadId && it.isSFNumber it.threadId == threadId && it.isSFNumber
} }
android.util.Log.d(TAG, "findConversationWithPhoneNumber listConversation = $listConversation") Log.d(TAG, "findConversationWithPhoneNumber listConversation = $listConversation")
if (listConversation.isNotEmpty()) { if (listConversation.isNotEmpty()) {
lastNumber = listConversation.first().title lastNumber = listConversation.first().title
} }
...@@ -184,14 +182,21 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -184,14 +182,21 @@ class SmsReceiver : BroadcastReceiver() {
} }
val photoUri = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(address) val photoUri = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(address)
val bitmap = context.getNotificationBitmap(photoUri) val bitmap = context.getNotificationBitmap(photoUri)
var notificationUserName = ""//通讯录如果有备注则优先展示备注,其次手机号
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
//最新消息会话
val conversation: Conversation = context.getConversations(threadId).firstOrNull() ?: return@post
Log.d(TAG, "handleMessage: conversation toJson = ${Gson().toJson(conversation)} ")
if(!PhoneFromUtil.isNumeric(conversation.userName)){
notificationUserName = conversation.userName
}
if (!context.isNumberBlocked(address)) { if (!context.isNumberBlocked(address)) {
val privateCursor = context.getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true) val privateCursor = context.getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
ensureBackgroundThread { ensureBackgroundThread {
val newMessageId: Long = context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId) val newMessageId: Long = context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId)
//最新消息会话
val conversation: Conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread
Log.d(TAG, "handleMessage: toJson = ${Gson().toJson(conversation)}")
if (aesPhoneNumber.isNotBlank() || body.contains("\u200B")) { if (aesPhoneNumber.isNotBlank() || body.contains("\u200B")) {
conversation.title = aesPhoneNumber conversation.title = aesPhoneNumber
conversation.isSFNumber = true conversation.isSFNumber = true
...@@ -205,11 +210,6 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -205,11 +210,6 @@ class SmsReceiver : BroadcastReceiver() {
val senderName = context.getNameFromAddress(address, privateCursor) val senderName = context.getNameFromAddress(address, privateCursor)
val phoneNumber = PhoneNumber(address, 0, "", address) val phoneNumber = PhoneNumber(address, 0, "", address)
/*if (aesPhoneNumber.isNotBlank()) {
senderName = context.getNameFromAddress(aesPhoneNumber, privateCursor)
phoneNumber = PhoneNumber(aesPhoneNumber, 0, "", aesPhoneNumber)
}*/
val participant = SimpleContact(0, 0, senderName, photoUri, arrayListOf(phoneNumber), ArrayList(), ArrayList()) val participant = SimpleContact(0, 0, senderName, photoUri, arrayListOf(phoneNumber), ArrayList(), ArrayList())
val participants = arrayListOf(participant) val participants = arrayListOf(participant)
val messageDate = (date / 1000).toInt() val messageDate = (date / 1000).toInt()
...@@ -238,17 +238,23 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -238,17 +238,23 @@ class SmsReceiver : BroadcastReceiver() {
context.updateConversationArchivedStatus(threadId, false) context.updateConversationArchivedStatus(threadId, false)
} }
refreshMessages() refreshMessages()
if (aesPhoneNumber.isNotBlank()) { Log.d(TAG, "handleMessage: notificationUserName = $notificationUserName aesPhoneNumber = $aesPhoneNumber address = $address")
if(notificationUserName.isNotEmpty()){
context.showReceivedMessageNotification(newMessageId, notificationUserName, body, threadId, bitmap)
}else if (aesPhoneNumber.isNotBlank()) {
context.showReceivedMessageNotification(newMessageId, aesPhoneNumber, body, threadId, bitmap) context.showReceivedMessageNotification(newMessageId, aesPhoneNumber, body, threadId, bitmap)
} else { } else {
context.showReceivedMessageNotification(newMessageId, address, body, threadId, bitmap) context.showReceivedMessageNotification(newMessageId, address, body, threadId, bitmap)
} }
} }
} }
Log.d(TAG, "SmsReceiver aesPhoneNumber 手机号是否加密 :${aesPhoneNumber}") Log.d(TAG, "SmsReceiver aesPhoneNumber 手机号是否加密 :${aesPhoneNumber}")
if (aesPhoneNumber.isNotBlank()) { Log.d(TAG, "SmsReceiver: notificationUserName = $notificationUserName aesPhoneNumber = $aesPhoneNumber address = $address")
if(notificationUserName.isNotEmpty()){
val tipPopup = MyPushWindow(context, notificationUserName, body)
tipPopup.show()
}else if (aesPhoneNumber.isNotBlank()) {
val tipPopup = MyPushWindow(context, aesPhoneNumber, body) val tipPopup = MyPushWindow(context, aesPhoneNumber, body)
tipPopup.show() tipPopup.show()
} else { } else {
...@@ -331,7 +337,7 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -331,7 +337,7 @@ class SmsReceiver : BroadcastReceiver() {
val buildNotification = builder.build() val buildNotification = builder.build()
notificationManager.notify(CALL_NOTIFICATION_ID, buildNotification) notificationManager.notify(CALL_NOTIFICATION_ID, buildNotification)
android.util.Log.d(TAG, "sendNotification: 发送通知栏消息推送") Log.d(TAG, "sendNotification: 发送通知栏消息推送")
} }
} }
......
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