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
adc54b18
Commit
adc54b18
authored
Dec 20, 2024
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:添加应用icon角标功能
parent
504b0350
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
94 deletions
+23
-94
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+0
-0
MainActivity.kt
...c/main/kotlin/com/secspace/sms/activities/MainActivity.kt
+23
-94
No files found.
app/src/main/AndroidManifest.xml
View file @
adc54b18
This diff is collapsed.
Click to expand it.
app/src/main/kotlin/com/secspace/sms/activities/MainActivity.kt
View file @
adc54b18
...
...
@@ -2,15 +2,9 @@ package com.secspace.sms.activities
import
android.annotation.SuppressLint
import
android.app.Activity
import
android.app.Notification
import
android.app.NotificationChannel
import
android.app.NotificationManager
import
android.app.role.RoleManager
import
android.content.Context
import
android.content.Intent
import
android.content.pm.PackageManager
import
android.content.pm.ShortcutManager
import
android.graphics.Color
import
android.database.Cursor
import
android.net.Uri
import
android.os.Build
import
android.os.Bundle
...
...
@@ -19,7 +13,6 @@ import android.text.TextUtils
import
android.util.Log
import
androidx.annotation.RequiresApi
import
androidx.coordinatorlayout.widget.CoordinatorLayout
import
androidx.core.app.NotificationCompat
import
androidx.lifecycle.lifecycleScope
import
com.secspace.sms.R
import
com.secspace.sms.adapters.ConversationsAdapter
...
...
@@ -88,88 +81,6 @@ class MainActivity : SimpleActivity() {
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
()
{
...
...
@@ -407,7 +318,10 @@ class MainActivity : SimpleActivity() {
}
private
fun
getNewConversations
(
cachedConversations
:
ArrayList
<
Conversation
>)
{
val
privateCursor
=
getMyContactsCursor
(
favoritesOnly
=
false
,
withPhoneNumbersOnly
=
true
)
var
privateCursor
:
Cursor
?
=
null
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
privateCursor
=
getMyContactsCursor
(
favoritesOnly
=
false
,
withPhoneNumbersOnly
=
true
)
}
val
privateContacts
=
MyContactsContentProvider
.
getSimpleContacts
(
this
@MainActivity
,
privateCursor
)
// Log.e(TAG, " getNewConversations privateContacts:${GsonUtil.parseListToJson(privateContacts)}")
...
...
@@ -463,11 +377,13 @@ class MainActivity : SimpleActivity() {
}
val
allConversations
=
conversationsDB
.
getNonArchived
()
as
ArrayList
<
Conversation
>
// Log.e(TAG, "----MainActivity----handleMessage allConversations:${GsonUtil.parseListToJson(allConversations)}")
// runOnUiThread {
setupConversations
(
allConversations
)
// }
// Log.e(TAG, "----MainActivity----handleMessage appRunCount:${config.appRunCount}")
val
readResult
=
conversations
.
count
{
!
it
.
read
}
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
setBadgeNum
(
readResult
)
}
if
(
config
.
appRunCount
==
1
)
{
conversations
.
map
{
it
.
threadId
}.
forEach
{
threadId
->
val
messages
=
getMessages
(
threadId
,
getImageResolutions
=
false
,
includeScheduledMessages
=
false
)
...
...
@@ -600,6 +516,19 @@ class MainActivity : SimpleActivity() {
}.
start
()
}
//https://developer.honor.com/cn/forum/topicdetail/topicid-3540765949296640
private
fun
setBadgeNum
(
num
:
Int
)
{
try
{
val
bunlde
=
Bundle
()
bunlde
.
putString
(
"package"
,
"com.secspace.sms"
)
// com.test.badge is your package name
bunlde
.
putString
(
"class"
,
"com.secspace.sms.activities.SplashActivity.Orange"
)
// 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
)
{
e
.
printStackTrace
()
}
}
@SuppressLint
(
"NotifyDataSetChanged"
)
private
fun
notifyDatasetChanged
()
{
getOrCreateConversationsAdapter
().
notifyDataSetChanged
()
...
...
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