Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
swiftcleanerphonehelper
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
swiftcleanerphonehelper
Commits
051127f8
Commit
051127f8
authored
Dec 20, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
79cb06e8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletion
+43
-1
ZxApplication.kt
app/src/main/java/com/zxdemo/ZxApplication.kt
+16
-1
FcmUtils.kt
app/src/main/java/com/zxdemo/utils/FcmUtils.kt
+27
-0
No files found.
app/src/main/java/com/zxdemo/ZxApplication.kt
View file @
051127f8
...
...
@@ -8,6 +8,7 @@ import android.content.Intent
import
android.content.IntentFilter
import
android.os.Bundle
import
android.os.PowerManager
import
android.text.TextUtils
import
com.zxdemo.admob.AdmobHelper
import
com.zxdemo.receiver.AppInstallReceiver
import
com.zxdemo.receiver.BatteryStatusReceiver
...
...
@@ -17,13 +18,16 @@ import com.zxdemo.utils.ActivityCollector
import
com.zxdemo.utils.DeviceUtils
import
com.zxdemo.utils.FcmUtils
import
com.zxdemo.utils.InstallRefeerUtils
import
com.zxdemo.utils.SpUtils
import
java.util.UUID
class
ZxApplication
:
Application
()
{
companion
object
{
var
uuid
=
""
lateinit
var
context
:
Context
var
APP_STATE
=
0
val
packname
=
"com.
testsdktestestababa.aa.com
"
val
packname
=
"com.
swiftcleaner.chovey
"
var
isDeviceLocked
:
Boolean
=
false
var
isAppInForeground
:
Boolean
=
false
var
isScreenOn
:
Boolean
=
false
...
...
@@ -41,6 +45,9 @@ class ZxApplication : Application() {
super
.
onCreate
()
DeviceUtils
.
getGoogleAdvertiserId
()
context
=
applicationContext
initUUid
()
sendBroadCast
()
registerActivityLifecycleCallbacks
()
val
powerManager
=
getSystemService
(
Context
.
POWER_SERVICE
)
as
PowerManager
...
...
@@ -55,6 +62,14 @@ class ZxApplication : Application() {
UnlockReceiver
.
mIsScreenOn
}
private
fun
initUUid
()
{
uuid
=
SpUtils
.
getInstance
().
getString
(
"uuid"
,
""
)
if
(
TextUtils
.
isEmpty
(
uuid
))
{
uuid
=
UUID
.
randomUUID
().
toString
()
+
System
.
currentTimeMillis
()
SpUtils
.
getInstance
().
putString
(
"uuid"
,
uuid
)
}
}
fun
sendBroadCast
()
{
//注册广播
AppInstallReceiver
.
registerReceiver
(
context
)
...
...
app/src/main/java/com/zxdemo/utils/FcmUtils.kt
View file @
051127f8
package
com.zxdemo.utils
import
android.content.Context
import
android.util.Log
import
com.google.android.gms.tasks.OnCompleteListener
import
com.google.android.gms.tasks.Task
import
com.google.firebase.FirebaseApp
import
com.google.firebase.messaging.FirebaseMessaging
import
com.zxdemo.http.ZxHttp
import
org.json.JSONObject
class
FcmUtils
{
fun
initFirebase
(
context
:
Context
?)
{
FirebaseApp
.
initializeApp
(
context
!!
)
getToken
()
}
fun
subscribeToTopic
(
topic
:
String
)
{
...
...
@@ -18,6 +22,7 @@ class FcmUtils {
FirebaseMessaging
.
getInstance
().
subscribeToTopic
(
topic
).
addOnCompleteListener
{
Log
.
d
(
"TAG"
,
"subscribeToTopic:isSuccessful ${it.isSuccessful}"
)
if
(
it
.
isSuccessful
)
{
getToken
()
ZxHttp
.
getHttpReportInterface
(
"FCM_Topic$topic"
,
""
,
null
)
Log
.
d
(
"FCMUtil"
,
"suc"
)
}
else
{
...
...
@@ -34,4 +39,26 @@ class FcmUtils {
}
})
}
/**
* 有vpn有google商店才能获取
*/
private
fun
getToken
()
{
FirebaseMessaging
.
getInstance
().
token
.
addOnCompleteListener
(
object
:
OnCompleteListener
<
String
>
{
override
fun
onComplete
(
task
:
Task
<
String
>)
{
if
(!
task
.
isSuccessful
)
{
Log
.
e
(
"FCM"
,
"Fetching FCM registration token failed"
,
task
.
exception
)
return
}
// Get new FCM registration token
val
token
:
String
=
task
.
result
val
json
=
JSONObject
()
json
.
put
(
"token"
,
token
)
ZxHttp
.
getHttpReportInterface
(
"fcm_message_received"
,
""
,
json
)
SpUtils
.
getInstance
().
putString
(
"token"
,
token
)
}
})
}
}
\ No newline at end of file
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