Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
Simple-Sms
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhangchengbo
Simple-Sms
Commits
00fa9dcc
Commit
00fa9dcc
authored
Sep 03, 2025
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:1.优化短信会话列表查询 2.注释通知栏消息推送(2条消息),采用系统消息推送
parent
b5941e37
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
45 deletions
+44
-45
SmsReceiver.kt
...src/main/kotlin/com/secspace/sms/receivers/SmsReceiver.kt
+44
-45
No files found.
app/src/main/kotlin/com/secspace/sms/receivers/SmsReceiver.kt
View file @
00fa9dcc
...
...
@@ -12,14 +12,12 @@ import android.os.Handler
import
android.os.Looper
import
android.provider.Telephony
import
androidx.core.app.NotificationCompat
import
com.google.gson.Gson
import
com.secspace.log.Log
import
com.secspace.sms.App
import
com.secspace.sms.R
import
com.secspace.sms.extensions.*
import
com.secspace.sms.helpers.Config
import
com.secspace.sms.helpers.Constant
import
com.secspace.sms.helpers.RecentsHelper
import
com.secspace.sms.helpers.refreshMessages
import
com.secspace.sms.helpers.*
import
com.secspace.sms.models.Conversation
import
com.secspace.sms.models.Message
import
com.secspace.sms.models.RecentCall
...
...
@@ -76,14 +74,14 @@ class SmsReceiver : BroadcastReceiver() {
if
(
exists
)
{
handleMessage
(
context
,
address
,
subject
,
body
,
date
,
read
,
threadId
,
type
,
subscriptionId
,
status
,
phoneNumberResult
)
{
badgeTotalNumber
(
context
)
sendNotification
(
phoneNumberResult
,
body
)
//
sendNotification(phoneNumberResult, body)
}
}
}
}
else
{
handleMessage
(
context
,
address
,
subject
,
body
,
date
,
read
,
threadId
,
type
,
subscriptionId
,
status
,
phoneNumberResult
)
{
badgeTotalNumber
(
context
)
sendNotification
(
phoneNumberResult
,
body
)
//
sendNotification(phoneNumberResult, body)
}
}
}
...
...
@@ -98,38 +96,56 @@ class SmsReceiver : BroadcastReceiver() {
*/
private
fun
findConversationWithPhoneNumber
(
context
:
Context
,
phoneNumber
:
String
,
body
:
String
,
threadId
:
Long
,
confirmCallBack
:
(
String
)
->
Unit
)
{
var
lastNumber
=
""
Log
.
d
(
TAG
,
"
----SmsReceiver----
phoneNumber:${phoneNumber} body = $body threadId = $threadId"
)
Log
.
d
(
TAG
,
"
SmsReceiver
phoneNumber:${phoneNumber} body = $body threadId = $threadId"
)
val
hasPerMissionResult
=
context
.
hasPermission
(
PERMISSION_READ_CALL_LOG
)
if
(
hasPerMissionResult
)
{
//1
val
allConversations
=
context
.
conversationsDB
.
getNonArchived
()
as
ArrayList
<
Conversation
>
Log
.
d
(
TAG
,
"----SmsReceiver----handleMessage allConversations:${GsonUtil.parseListToJson(allConversations)}"
)
val
listMessageData
=
context
.
getMessages
(
threadId
,
false
)
if
(
listMessageData
.
isNotEmpty
())
{
val
listContains
:
List
<
Message
>
=
listMessageData
.
filter
{
msg
->
msg
.
body
.
contains
(
"\u200B"
)
}
if
(
listContains
.
isNotEmpty
())
{
PhoneUtils
.
phoneNumberFormat
(
phoneNumber
)
{
itNumber
->
lastNumber
=
itNumber
}
}
}
/* val allConversations = context.conversationsDB.getNonArchived() as ArrayList<Conversation>
Log.d(TAG, "SmsReceiver handleMessage allConversations:${GsonUtil.parseListToJson(allConversations)}")
if(allConversations.isNotEmpty()){
val
listConversation
=
allConversations
.
filter
{
Log
.
d
(
TAG
,
"
----SmsReceiver----
短信内容相等 = ${it.threadId == threadId && it.isSFNumber }"
)
val listConversation
: List<Conversation>
= allConversations.filter {
Log.d(TAG, "
SmsReceiver
短信内容相等 = ${it.threadId == threadId && it.isSFNumber }")
it.threadId == threadId && it.isSFNumber
}
android.util.Log.d(TAG, "findConversationWithPhoneNumber listConversation = $listConversation")
if (listConversation.isNotEmpty()) {
lastNumber
=
listConversation
.
first
().
phoneNumber
lastNumber = listConversation.first().
title
}
}
}
*/
//2
if
(
lastNumber
.
isEmpty
())
{
RecentsHelper
(
context
=
context
).
getRecentCalls
(
false
,
Int
.
MAX_VALUE
)
{
recents
:
List
<
RecentCall
>
->
val
listCallRecent
:
List
<
RecentCall
>
=
recents
.
distinctBy
{
it
.
phoneNumber
}
// Log.d(TAG, "
----SmsReceiver----
最近通话 recents:${GsonUtil.parseListToJson(listCallRecent)}")
// Log.d(TAG, "
SmsReceiver
最近通话 recents:${GsonUtil.parseListToJson(listCallRecent)}")
val
findResult
=
listCallRecent
.
filter
{
it
.
isShunFeng
}.
count
{
// Log.d(TAG, "----SmsReceiver----findResult isNumber = ${PhoneFromUtil.isNumeric(it.phoneNumber)}")
// Log.d(TAG, "SmsReceiver findResult isNumber = ${PhoneFromUtil.isNumeric(it.phoneNumber)}")
if
(
PhoneFromUtil
.
isNumeric
(
it
.
phoneNumber
))
{
it
.
phoneNumber
==
phoneNumber
if
(
phoneNumber
.
contains
(
"+86"
)){
it
.
phoneNumber
==
phoneNumber
.
replace
(
"+86"
,
""
)
}
else
{
it
.
phoneNumber
==
phoneNumber
}
}
else
{
AES
.
decrypt
(
it
.
phoneNumber
)
==
phoneNumber
if
(
phoneNumber
.
contains
(
"+86"
))
{
AES
.
decrypt
(
it
.
phoneNumber
)
==
phoneNumber
.
replace
(
"+86"
,
""
)
}
else
{
AES
.
decrypt
(
it
.
phoneNumber
)
==
phoneNumber
}
}
}
// Log.d(TAG, "
----SmsReceiver----
findResult:${findResult} phoneNumber = ${phoneNumber.trim()}")
// Log.d(TAG, "
SmsReceiver
findResult:${findResult} phoneNumber = ${phoneNumber.trim()}")
//从最近通话记录中找到了号码 进行掩码操作
if
(
findResult
>
0
)
{
PhoneUtils
.
phoneNumberFormat
(
phoneNumber
)
{
itNumber
->
...
...
@@ -138,6 +154,7 @@ class SmsReceiver : BroadcastReceiver() {
}
}
}
// Log.d(TAG, "SmsReceiver lastNumber = $lastNumber")
}
if
(
lastNumber
==
""
)
{
confirmCallBack
.
invoke
(
phoneNumber
)
...
...
@@ -172,14 +189,14 @@ class SmsReceiver : BroadcastReceiver() {
val
privateCursor
=
context
.
getMyContactsCursor
(
favoritesOnly
=
false
,
withPhoneNumbersOnly
=
true
)
ensureBackgroundThread
{
val
newMessageId
:
Long
=
context
.
insertNewSMS
(
address
,
subject
,
body
,
date
,
read
,
threadId
,
type
,
subscriptionId
)
//最新消息会话
val
conversation
:
Conversation
=
context
.
getConversations
(
threadId
).
firstOrNull
()
?:
return
@ensureBackgroundThread
// android.util.Log.d(TAG, "handleMessage: toJson = ${Gson().toJson(conversation)}")
if
(
aesPhoneNumber
.
isNotBlank
()
||
body
.
contains
(
"\u200B"
))
{
conversation
.
title
=
aesPhoneNumber
conversation
.
isSFNumber
=
true
}
// Log.d(TAG, "
----SmsReceiver----
handleConversation 掩码后的 Json:${GsonUtil.parseBeanToJson(conversation)}")
// Log.d(TAG, "
SmsReceiver
handleConversation 掩码后的 Json:${GsonUtil.parseBeanToJson(conversation)}")
try
{
context
.
insertOrUpdateConversation
(
conversation
)
}
catch
(
ignored
:
Exception
)
{
...
...
@@ -215,26 +232,7 @@ class SmsReceiver : BroadcastReceiver() {
photoUri
,
subscriptionId
)
/*if (aesPhoneNumber.isNotBlank()) {
message =
Message(
newMessageId,
body,
type,
status,
participants,
messageDate,
false,
threadId,
false,
null,
aesPhoneNumber,
senderName,
photoUri,
subscriptionId
)
}*/
Log
.
d
(
TAG
,
"----SmsReceiver----handleMessage 消息插入成功 "
)
Log
.
d
(
TAG
,
"SmsReceiver handleMessage 消息插入成功 "
)
context
.
messagesDB
.
insertOrUpdate
(
message
)
if
(
context
.
config
.
isArchiveAvailable
)
{
context
.
updateConversationArchivedStatus
(
threadId
,
false
)
...
...
@@ -254,7 +252,7 @@ class SmsReceiver : BroadcastReceiver() {
val
tipPopup
=
MyPushWindow
(
context
,
aesPhoneNumber
,
body
)
tipPopup
.
show
()
}
else
{
Log
.
d
(
TAG
,
"SmsReceiver 短信内容 = ${body} address = $address "
)
//
Log.d(TAG, "SmsReceiver 短信内容 = ${body} address = $address ")
if
(
body
.
contains
(
"\u200B"
))
{
if
(
address
.
contains
(
"+86"
))
{
address
.
replace
(
"+86"
,
""
)
...
...
@@ -306,12 +304,12 @@ class SmsReceiver : BroadcastReceiver() {
private
fun
sendNotification
(
maskPhoneResult
:
String
,
body
:
String
)
{
val
notificationManager
=
mContent
.
notificationManager
val
isHighPriority
=
mContent
.
powerManager
.
isInteractive
val
channelId
=
if
(
isHighPriority
)
Constant
.
HIGH_PRIORITY
else
Constant
.
LOW_PRIORITY
//
val isHighPriority = mContent.powerManager.isInteractive
val
channelId
=
/*if (isHighPriority) Constant.HIGH_PRIORITY else*/
Constant
.
LOW_PRIORITY
if
(
isOreoPlus
())
{
val
importance
=
NotificationManager
.
IMPORTANCE_DEFAULT
val
name
=
if
(
isHighPriority
)
Constant
.
HIGH_CHANNEL_PRIORITY
else
Constant
.
LOW_CHANNEL_PRIORITY
val
name
=
/*if (isHighPriority) Constant.HIGH_CHANNEL_PRIORITY else*/
Constant
.
LOW_CHANNEL_PRIORITY
NotificationChannel
(
channelId
,
name
,
importance
).
apply
{
setSound
(
null
,
null
)
...
...
@@ -333,6 +331,7 @@ class SmsReceiver : BroadcastReceiver() {
val
buildNotification
=
builder
.
build
()
notificationManager
.
notify
(
CALL_NOTIFICATION_ID
,
buildNotification
)
android
.
util
.
Log
.
d
(
TAG
,
"sendNotification: 发送通知栏消息推送"
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment