Commit 051127f8 authored by wanglei's avatar wanglei

...

parent 79cb06e8
......@@ -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)
......
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
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