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