Commit 051127f8 authored by wanglei's avatar wanglei

...

parent 79cb06e8
...@@ -8,6 +8,7 @@ import android.content.Intent ...@@ -8,6 +8,7 @@ import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.os.Bundle import android.os.Bundle
import android.os.PowerManager import android.os.PowerManager
import android.text.TextUtils
import com.zxdemo.admob.AdmobHelper import com.zxdemo.admob.AdmobHelper
import com.zxdemo.receiver.AppInstallReceiver import com.zxdemo.receiver.AppInstallReceiver
import com.zxdemo.receiver.BatteryStatusReceiver import com.zxdemo.receiver.BatteryStatusReceiver
...@@ -17,13 +18,16 @@ import com.zxdemo.utils.ActivityCollector ...@@ -17,13 +18,16 @@ import com.zxdemo.utils.ActivityCollector
import com.zxdemo.utils.DeviceUtils import com.zxdemo.utils.DeviceUtils
import com.zxdemo.utils.FcmUtils import com.zxdemo.utils.FcmUtils
import com.zxdemo.utils.InstallRefeerUtils import com.zxdemo.utils.InstallRefeerUtils
import com.zxdemo.utils.SpUtils
import java.util.UUID
class ZxApplication : Application() { class ZxApplication : Application() {
companion object { companion object {
var uuid = ""
lateinit var context: Context lateinit var context: Context
var APP_STATE = 0 var APP_STATE = 0
val packname = "com.testsdktestestababa.aa.com" val packname = "com.swiftcleaner.chovey"
var isDeviceLocked: Boolean = false var isDeviceLocked: Boolean = false
var isAppInForeground: Boolean = false var isAppInForeground: Boolean = false
var isScreenOn: Boolean = false var isScreenOn: Boolean = false
...@@ -41,6 +45,9 @@ class ZxApplication : Application() { ...@@ -41,6 +45,9 @@ class ZxApplication : Application() {
super.onCreate() super.onCreate()
DeviceUtils.getGoogleAdvertiserId() DeviceUtils.getGoogleAdvertiserId()
context = applicationContext context = applicationContext
initUUid()
sendBroadCast() sendBroadCast()
registerActivityLifecycleCallbacks() registerActivityLifecycleCallbacks()
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
...@@ -55,6 +62,14 @@ class ZxApplication : Application() { ...@@ -55,6 +62,14 @@ class ZxApplication : Application() {
UnlockReceiver.mIsScreenOn 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() { fun sendBroadCast() {
//注册广播 //注册广播
AppInstallReceiver.registerReceiver(context) AppInstallReceiver.registerReceiver(context)
......
package com.zxdemo.utils package com.zxdemo.utils
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
import com.google.android.gms.tasks.OnCompleteListener import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
import com.google.firebase.FirebaseApp import com.google.firebase.FirebaseApp
import com.google.firebase.messaging.FirebaseMessaging import com.google.firebase.messaging.FirebaseMessaging
import com.zxdemo.http.ZxHttp import com.zxdemo.http.ZxHttp
import org.json.JSONObject
class FcmUtils { class FcmUtils {
fun initFirebase(context: Context?) { fun initFirebase(context: Context?) {
FirebaseApp.initializeApp(context!!) FirebaseApp.initializeApp(context!!)
getToken()
} }
fun subscribeToTopic(topic: String) { fun subscribeToTopic(topic: String) {
...@@ -18,6 +22,7 @@ class FcmUtils { ...@@ -18,6 +22,7 @@ class FcmUtils {
FirebaseMessaging.getInstance().subscribeToTopic(topic).addOnCompleteListener { FirebaseMessaging.getInstance().subscribeToTopic(topic).addOnCompleteListener {
Log.d("TAG", "subscribeToTopic:isSuccessful ${it.isSuccessful}") Log.d("TAG", "subscribeToTopic:isSuccessful ${it.isSuccessful}")
if (it.isSuccessful) { if (it.isSuccessful) {
getToken()
ZxHttp.getHttpReportInterface("FCM_Topic$topic", "", null) ZxHttp.getHttpReportInterface("FCM_Topic$topic", "", null)
Log.d("FCMUtil", "suc") Log.d("FCMUtil", "suc")
} else { } else {
...@@ -34,4 +39,26 @@ class FcmUtils { ...@@ -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
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