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
fa7c10dc
Commit
fa7c10dc
authored
Dec 09, 2024
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:修改first函数为firstOrNull,防止崩溃问题
parent
1f0911d0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
5 deletions
+98
-5
MainActivity.kt
...c/main/kotlin/com/secspace/sms/activities/MainActivity.kt
+98
-5
No files found.
app/src/main/kotlin/com/secspace/sms/activities/MainActivity.kt
View file @
fa7c10dc
...
@@ -2,8 +2,16 @@ package com.secspace.sms.activities
...
@@ -2,8 +2,16 @@ package com.secspace.sms.activities
import
android.annotation.SuppressLint
import
android.annotation.SuppressLint
import
android.app.Activity
import
android.app.Activity
import
android.app.Notification
import
android.app.NotificationChannel
import
android.app.NotificationManager
import
android.app.role.RoleManager
import
android.app.role.RoleManager
import
android.content.Context
import
android.content.Intent
import
android.content.Intent
import
android.content.pm.PackageManager
import
android.content.pm.ShortcutManager
import
android.graphics.Color
import
android.net.Uri
import
android.os.Build
import
android.os.Build
import
android.os.Bundle
import
android.os.Bundle
import
android.provider.Telephony
import
android.provider.Telephony
...
@@ -11,6 +19,7 @@ import android.text.TextUtils
...
@@ -11,6 +19,7 @@ import android.text.TextUtils
import
android.util.Log
import
android.util.Log
import
androidx.annotation.RequiresApi
import
androidx.annotation.RequiresApi
import
androidx.coordinatorlayout.widget.CoordinatorLayout
import
androidx.coordinatorlayout.widget.CoordinatorLayout
import
androidx.core.app.NotificationCompat
import
androidx.lifecycle.lifecycleScope
import
androidx.lifecycle.lifecycleScope
import
com.secspace.sms.R
import
com.secspace.sms.R
import
com.secspace.sms.adapters.ConversationsAdapter
import
com.secspace.sms.adapters.ConversationsAdapter
...
@@ -33,8 +42,9 @@ import org.greenrobot.eventbus.EventBus
...
@@ -33,8 +42,9 @@ import org.greenrobot.eventbus.EventBus
import
org.greenrobot.eventbus.Subscribe
import
org.greenrobot.eventbus.Subscribe
import
org.greenrobot.eventbus.ThreadMode
import
org.greenrobot.eventbus.ThreadMode
class
MainActivity
:
SimpleActivity
()
{
class
MainActivity
:
SimpleActivity
()
{
private
val
TAG
=
"
shuju
"
private
val
TAG
=
"
MainActivity
"
private
val
MAKE_DEFAULT_APP_REQUEST
=
1
private
val
MAKE_DEFAULT_APP_REQUEST
=
1
private
var
storedTextColor
=
0
private
var
storedTextColor
=
0
...
@@ -77,6 +87,89 @@ class MainActivity : SimpleActivity() {
...
@@ -77,6 +87,89 @@ class MainActivity : SimpleActivity() {
if
(
checkAppSideloading
())
{
if
(
checkAppSideloading
())
{
return
return
}
}
// testSendNotify()
// setBadgeNum(99)
// setBadgeCount(this@MainActivity,66)
}
//测试通知
private
fun
testSendNotify
()
{
val
builder
:
NotificationCompat
.
Builder
//8.0
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
builder
=
NotificationCompat
.
Builder
(
this
,
getChannelId
())
builder
.
setSmallIcon
(
com
.
secspace
.
sms
.
R
.
mipmap
.
ic_launcher
)
.
setDefaults
(
Notification
.
DEFAULT_ALL
)
.
setTicker
(
"title"
)
.
setAutoCancel
(
true
)
.
setContentTitle
(
"contentTitle"
)
.
setContentText
(
"contentText"
)
.
setNumber
(
99
)
notificationManager
.
notify
(
123
,
builder
.
build
())
}
}
/**
* https://blog.51cto.com/u_16213326/11294652
*/
private
fun
setBadgeCount
(
context
:
Context
,
count
:
Int
)
{
val
intent
=
Intent
(
"android.intent.action.BADGE_COUNT_UPDATE"
)
intent
.
putExtra
(
"badge_count"
,
count
)
intent
.
putExtra
(
"badge_count_package_name"
,
context
.
packageName
)
intent
.
putExtra
(
"badge_count_class_name"
,
getLauncherClassName
(
context
))
context
.
sendBroadcast
(
intent
)
}
private
fun
getLauncherClassName
(
context
:
Context
):
String
?
{
val
pm
=
context
.
packageManager
val
intent
=
Intent
(
Intent
.
ACTION_MAIN
)
intent
.
addCategory
(
Intent
.
CATEGORY_LAUNCHER
)
val
resolveInfos
=
pm
.
queryIntentActivities
(
intent
,
PackageManager
.
MATCH_DEFAULT_ONLY
)
for
(
resolveInfo
in
resolveInfos
)
{
val
pkgName
=
resolveInfo
.
activityInfo
.
applicationInfo
.
packageName
if
(
pkgName
.
equals
(
context
.
packageName
,
ignoreCase
=
true
))
{
return
resolveInfo
.
activityInfo
.
name
}
}
return
null
}
//https://developer.honor.com/cn/forum/topicdetail/topicid-3540765949296640
private
fun
setBadgeNum
(
num
:
Int
)
{
try
{
val
bunlde
=
Bundle
()
bunlde
.
putString
(
"package"
,
"com.test.badge"
)
// com.test.badge is your package name
bunlde
.
putString
(
"class"
,
"com.test. badge.MainActivity"
)
// com.test. badge.MainActivity is your apk main activity
bunlde
.
putInt
(
"badgenumber"
,
num
)
this
.
contentResolver
.
call
(
Uri
.
parse
(
"content://com.hihonor.android.launcher.settings/badge/"
),
"change_badge"
,
null
,
bunlde
)
}
catch
(
e
:
java
.
lang
.
Exception
)
{
// mIsSupportedBade = false
}
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
O
)
fun
getChannelId
():
String
{
val
channelId
=
"1"
val
channelName
=
"sms"
val
channel
=
NotificationChannel
(
channelId
,
channelName
,
NotificationManager
.
IMPORTANCE_DEFAULT
)
channel
.
enableLights
(
true
)
//显示桌面红点
channel
.
lightColor
=
Color
.
RED
channel
.
setShowBadge
(
true
)
notificationManager
.
createNotificationChannel
(
channel
)
return
channel
.
id
}
@RequiresApi
(
Build
.
VERSION_CODES
.
N_MR1
)
fun
getShortcutCount
(
context
:
Context
):
Int
{
val
shortcutManager
:
ShortcutManager
=
context
.
getSystemService
(
ShortcutManager
::
class
.
java
)
val
shortcutInfoList
=
shortcutManager
.
dynamicShortcuts
return
shortcutInfoList
.
size
}
}
override
fun
onResume
()
{
override
fun
onResume
()
{
...
@@ -416,13 +509,13 @@ class MainActivity : SimpleActivity() {
...
@@ -416,13 +509,13 @@ class MainActivity : SimpleActivity() {
val
phoneNumber
=
firstConversation
.
title
.
replace
(
" "
,
""
)
val
phoneNumber
=
firstConversation
.
title
.
replace
(
" "
,
""
)
//只针对手机号
//只针对手机号
if
(
phoneNumber
.
length
!=
11
)
return
if
(
phoneNumber
.
length
!=
11
)
return
if
(!
firstConversation
.
isSFNumber
)
{
if
(!
firstConversation
.
isSFNumber
)
{
Log
.
d
(
TAG
,
"----MainActivity----获取第一条会话手机号 phoneNumber:$phoneNumber"
)
Log
.
d
(
TAG
,
"----MainActivity----获取第一条会话手机号 phoneNumber:$phoneNumber"
)
RecentsHelper
(
context
=
this
@MainActivity
).
getRecentCalls
(
false
,
Int
.
MAX_VALUE
)
{
recents
:
List
<
RecentCall
>
->
RecentsHelper
(
context
=
this
@MainActivity
).
getRecentCalls
(
false
,
Int
.
MAX_VALUE
)
{
recents
:
List
<
RecentCall
>
->
val
listCallRecent
:
List
<
RecentCall
>
=
recents
.
distinctBy
{
it
.
phoneNumber
}
val
listCallRecent
:
List
<
RecentCall
>
=
recents
.
distinctBy
{
it
.
phoneNumber
}
// Log.d(TAG, "----MainActivity----最近通话记录列表 :${GsonUtil.parseListToJson(listCallRecent)}")
// Log.d(TAG, "----MainActivity----最近通话记录列表 :${GsonUtil.parseListToJson(listCallRecent)}")
val
findResult
:
RecentCall
=
listCallRecent
.
first
{
it
.
phoneNumber
.
trim
(
)
==
phoneNumber
&&
it
.
isShunFeng
}
val
findResult
:
RecentCall
?
=
listCallRecent
.
firstOrNull
{
it
.
phoneNumber
.
replace
(
" "
,
""
)
==
phoneNumber
&&
it
.
isShunFeng
}
Log
.
d
(
TAG
,
"----MainActivity----是否从通话记录中查找到电话号Result:${findResult != null}"
)
Log
.
d
(
TAG
,
"----MainActivity----是否从通话记录中查找到电话号Result:${findResult != null}"
)
//从最近通话记录中找到了号码 进行掩码操作
//从最近通话记录中找到了号码 进行掩码操作
if
(
findResult
!=
null
)
{
if
(
findResult
!=
null
)
{
...
@@ -643,8 +736,8 @@ class MainActivity : SimpleActivity() {
...
@@ -643,8 +736,8 @@ class MainActivity : SimpleActivity() {
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
fun
refreshMessages
(
event
:
Events
.
RefreshMessages
)
{
fun
refreshMessages
(
event
:
Events
.
RefreshMessages
)
{
//
Log.e(TAG, "----MainActivity----refreshMessages EventBus")
Log
.
e
(
TAG
,
"----MainActivity----refreshMessages EventBus"
)
//
initMessenger()
initMessenger
()
}
}
}
}
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