Commit 1ee22530 authored by wanglei's avatar wanglei

======同步clean master max的fcm修改=======

parent 02d6b197
......@@ -18,10 +18,7 @@ import com.google.android.gms.ads.identifier.AdvertisingIdClient
import com.google.firebase.FirebaseApp
import com.test.basd.supercleanermax.activity.splash.NewSplashActivity
import com.test.basd.supercleanermax.display.ActionBroadcast.Companion.initBroadcast
import com.test.basd.supercleanermax.display.NotificationService
import com.test.basd.supercleanermax.display.NotificationUtils
import com.test.basd.supercleanermax.display.fcm.FcmHelper
import com.test.basd.supercleanermax.display.fcm.NotificationJobService
import com.test.basd.supercleanermax.helps.BaseApplication
import com.test.basd.supercleanermax.helps.ComUtils.requestCfg
import com.test.basd.supercleanermax.helps.ConfigHelper
......@@ -78,17 +75,6 @@ class MyApplication : BaseApplication() {
FcmHelper.getToken()
FcmHelper.subscribeToTopic()
FcmHelper.startFCMCheckAlarm(this)
initJob()
}
private fun initJob() {
val jobScheduler = getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
val job = JobInfo.Builder(0, ComponentName(this, NotificationJobService::class.java))
.setMinimumLatency(0L)
.setOverrideDeadline(0L)
.setPersisted(true)
.build()
jobScheduler.schedule(job)
}
@SuppressLint("UnspecifiedRegisterReceiverFlag")
......
......@@ -88,11 +88,12 @@ class BatteryInfoActivity : BaseActivity<ActivityBatteryInfoBinding>() {
}
binding.btOk.setOnClickListener {
binding.btOk.setBackgroundResource(R.drawable.bg_shape_set_click)
startActivity(Intent(this, ResultActivity::class.java).apply {
putExtra("from", AFunOb.BATTERY_INFO)
})
finish()
AdmobUtils.showInterstitialAd(this) {
startActivity(Intent(this, ResultActivity::class.java).apply {
putExtra("from", AFunOb.BATTERY_INFO)
})
finish()
}
}
binding.ivBack.setOnClickListener {
AdmobUtils.showInterstitialAd(this@BatteryInfoActivity) {
......@@ -124,8 +125,8 @@ class BatteryInfoActivity : BaseActivity<ActivityBatteryInfoBinding>() {
private inner class BatteryReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val current = intent?.extras?.getInt("level")?:0
val total = intent?.extras?.getInt("scale")?:0
val current = intent?.extras?.getInt("level") ?: 0
val total = intent?.extras?.getInt("scale") ?: 0
val percent = current * 100 / total
if (percent >= 30) {
binding.imagePower.setImageResource(R.mipmap.batteryl)
......@@ -165,32 +166,27 @@ class BatteryInfoActivity : BaseActivity<ActivityBatteryInfoBinding>() {
}
private fun checkFlashLight() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
cm.registerTorchCallback(object : CameraManager.TorchCallback() {
override fun onTorchModeChanged(cameraId: String, enabled: Boolean) {
super.onTorchModeChanged(cameraId, enabled)
if (cameraId == this@BatteryInfoActivity.cameraId) {
if (enabled && !isTorchOn) {
isTorchOn = true
binding.switchThree.isChecked = true
} else if (!enabled && isTorchOn) {
isTorchOn = false
binding.switchThree.isChecked = false
}
cm.registerTorchCallback(object : CameraManager.TorchCallback() {
override fun onTorchModeChanged(cameraId: String, enabled: Boolean) {
super.onTorchModeChanged(cameraId, enabled)
if (cameraId == this@BatteryInfoActivity.cameraId) {
if (enabled && !isTorchOn) {
isTorchOn = true
binding.switchThree.isChecked = true
} else if (!enabled && isTorchOn) {
isTorchOn = false
binding.switchThree.isChecked = false
}
}
}, null)
} else {
Toast.makeText(this, "don't support you phone", Toast.LENGTH_SHORT).show()
}
}
}, null)
}
private fun turnOnFlashLight() {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
cm.setTorchMode(cameraId, true)
} // 打开手电筒
cm.setTorchMode(cameraId, true)
// 打开手电筒
} catch (e: CameraAccessException) {
e.printStackTrace()
}
......@@ -198,9 +194,8 @@ class BatteryInfoActivity : BaseActivity<ActivityBatteryInfoBinding>() {
private fun turnOffFlashLight() {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
cm.setTorchMode(cameraId, false)
} // 打开手电筒
cm.setTorchMode(cameraId, false)
// 打开手电筒
} catch (e: CameraAccessException) {
e.printStackTrace()
}
......
......@@ -17,7 +17,6 @@ import com.test.basd.supercleanermax.fragment.BatteryFragment
import com.test.basd.supercleanermax.fragment.HomeFragment
import com.test.basd.supercleanermax.fragment.ToolsFragment
import com.test.basd.supercleanermax.helps.BaseActivity
import com.test.basd.supercleanermax.helps.ads.AdmobUtils
import com.test.basd.supercleanermax.view.RateStarPop
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
......@@ -47,7 +46,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
override fun initView() {
BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
AdmobUtils.loadNativeAd()
// binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
binding.idVp.run {
adapter = object : FragmentStateAdapter(this@MainActivity) {
......
......@@ -2,6 +2,10 @@ package com.test.basd.supercleanermax.activity.splash
import android.Manifest
import android.annotation.SuppressLint
import android.app.job.JobInfo
import android.app.job.JobScheduler
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Build
......@@ -14,6 +18,7 @@ import com.blankj.utilcode.util.BarUtils
import com.test.basd.supercleanermax.databinding.ActivityLayoutSplashBinding
import com.test.basd.supercleanermax.display.CloseNotificationReceiver
import com.test.basd.supercleanermax.display.NotificationHelper
import com.test.basd.supercleanermax.display.fcm.NotificationJobService
import com.test.basd.supercleanermax.helps.BaseActivity
import com.test.basd.supercleanermax.helps.ConfigHelper
import com.test.basd.supercleanermax.helps.LogEx
......@@ -62,13 +67,22 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
}
override fun onAgreePrivacy() {
initJob()
MainScope().launch(Dispatchers.IO) {
ConfigHelper.appList = AppUtils.getAppsInfo().shuffled()
}
mProgressManager?.startProgress()
loadAd()
}
private fun initJob() {
val jobScheduler = getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
val job = JobInfo.Builder(0, ComponentName(this, NotificationJobService::class.java))
.setMinimumLatency(0L)
.setOverrideDeadline(0L)
.setPersisted(true)
.build()
jobScheduler.schedule(job)
}
override fun onProgressMax() {
Handler().postDelayed({
......@@ -93,7 +107,6 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
}
}
AdmobUtils.loadInterstitialAd(this)
// AdmobUtils.loadNativeAd()
}
override fun onNewIntent(intent: Intent) {
......
......@@ -55,7 +55,6 @@ object NotificationHelper {
*/
val supportNotification = arrayListOf(
ID_JUNK_CLEAN_PUSH,
// ID_VIRUS_PUSH,
ID_LARGE_FILE_PUSH,
ID_BATTERY_PUSH,
ID_CLEAN_NOTIFICATION,
......@@ -66,8 +65,6 @@ object NotificationHelper {
ID_RECENT_USE_APP,
ID_SIMILAR_IMAGE,
ID_CLEAN_SPEAKER,
// ID_BATTERY_OPTIMIZATION,
// ID_PHONE_ACCELERATE,//被动推送加入主动推送列表
)
/**
......@@ -99,7 +96,10 @@ object NotificationHelper {
SPUtils.getInstance().getString("push_circle_order", initJson)
tempList.addAll(filterList)
} else {
val array = Gson().fromJson(json, object : TypeToken<Array<Int>>() {})
var array = emptyArray<Int>()
runCatching {
array = Gson().fromJson(json, object : TypeToken<Array<Int>>() {})
}
tempList.addAll(array)
if (tempList.isEmpty()) {
......@@ -132,19 +132,6 @@ object NotificationHelper {
remoteViews.setTextViewText(R.id.tv_btn, "Clean up")
}
// ID_VIRUS_PUSH -> {
// remoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.virus)
// remoteViews.setTextViewText(R.id.tv_desc, "Protect your device and privacy, scan for virus threats now!")
// remoteViews.setTextViewText(R.id.tv_btn, "Scan")
// }
// ID_BATTERY_OPTIMIZATION -> {
// remoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.battery)
// val random = Random.nextInt(0, 50)
// remoteViews.setTextViewText(R.id.tv_desc, "$random Apps are consuming photo power")
// remoteViews.setTextViewText(R.id.tv_btn, "Optimize")
// }
ID_LARGE_FILE_PUSH -> {
remoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.large_home)
remoteViews.setTextViewText(R.id.tv_desc, "Clean big files to free up storage space")
......@@ -219,12 +206,6 @@ object NotificationHelper {
remoteViews.setTextViewText(R.id.tv_btn, "View")
}
// ID_PHONE_ACCELERATE -> {
// remoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.memory)
// remoteViews.setTextViewText(R.id.tv_desc, "Ram usage reached $extra%, optimize now!")
// remoteViews.setTextViewText(R.id.tv_btn, "Optimize")
// }
else -> {
return
}
......
......@@ -13,13 +13,15 @@ class FCMCheckReceiver : BroadcastReceiver() {
// 检查FCM连接并重新连接(如果需要)
// 这里可以根据具体需求自行实现
val boolean = FirebaseMessaging.getInstance().isAutoInitEnabled()
val boolean = FirebaseMessaging.getInstance().isAutoInitEnabled
FcmHelper.getToken()
if (boolean) {
EventHelper.event("fcm_autoInit_suc")
} else {
EventHelper.event("fcm_autoInit_fail")
}
Log.d("FcmHelper", "FCMCheckReceiver: $boolean")
}
}
......@@ -21,16 +21,18 @@ object FcmHelper {
FirebaseMessaging.getInstance().subscribeToTopic("news")
.addOnCompleteListener { task: Task<Void?> ->
if (task.isSuccessful) {
EventHelper.event("fcm_subscribed_suc", "news")
EventHelper.event("fcm_subscribed_suc","news")
Log.d(TAG, "Subscribed to topic: TOPIC_NAME")
} else {
EventHelper.event("fcm_subscribed_fail")
Log.e(TAG, "Failed to subscribe to topic: TOPIC_NAME", task.exception)
}
}
}
fun getToken() {
fun getToken(){
FirebaseMessaging.getInstance().token
.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
......@@ -40,18 +42,22 @@ object FcmHelper {
}
// Get new FCM registration token
val token = task.result
EventHelper.event("fcm_token_suc", token)
EventHelper.event("fcm_token_suc",token)
Log.d(TAG, "token: $token")
})
}
@SuppressLint("UnspecifiedImmutableFlag")
fun startFCMCheckAlarm(context: Context) {
val intervalMillis = (15 * 60 * 1000).toLong() // 1分钟
// 判断是否已经在运行
val intent = Intent(context, FCMCheckReceiver::class.java)
val isRunning =
PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE) != null
PendingIntent.getBroadcast(
context,
0,
intent,
PendingIntent.FLAG_IMMUTABLE
) != null
if (isRunning) {
Log.d(TAG, "FCM check alarm is already running")
return
......
......@@ -21,10 +21,11 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
FcmHelper.startFCMCheckAlarm(this)
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.S) {
FcmHelper.getToken()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
return
}
initJob()
}
......
......@@ -119,7 +119,6 @@ object AdmobUtils {
obj.put("req_id", reqId)
obj.put("ad_type", "openAd")
EventHelper.event("ad_pull_start", ext = obj)
AppOpenAd.load(
BaseApplication.context,
ConfigHelper.openAdmobId,
......@@ -132,14 +131,14 @@ object AdmobUtils {
pull(ad.responseInfo, "openAd", reqId = reqId)
ad.onPaidEventListener = EventOnPaidEventListener(ad)
// Log.e("MXL", "OpenonAdLoaded: ")
// Log.e("MXL", "拉取成功: ", )
}
override fun onAdFailedToLoad(p0: LoadAdError) {
mOpenAd = null
onLoad?.invoke()
Log.d("glc", "开屏拉取失败:" + p0.message)
pull(p0.responseInfo, "openAd", p0.message, reqId = reqId)
//Log.e("MXL", "onAdFailedToLoad: " + p0.message)
// Log.e("MXL", "onAdFailedToLoad: " + p0.message)
//ToastUtils.showShort("开屏拉取失败" + p0.message)
}
})
......
......@@ -587,7 +587,7 @@
android:layout_marginBottom="40dp"
android:background="@color/theme_color"
android:gravity="center"
android:text="Go it"
android:text="Go It"
android:textAllCaps="false"
android:textColor="#ffffffff"
android:textSize="19sp"
......
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