Commit dcdf0978 authored by leichao.gao's avatar leichao.gao

增加推送限制

parent d80c22fe
...@@ -55,6 +55,7 @@ class MyApplication : BaseApplication() { ...@@ -55,6 +55,7 @@ class MyApplication : BaseApplication() {
FCMManager.initFirebase(this) FCMManager.initFirebase(this)
FCMManager.subscribeToTopic(topic) FCMManager.subscribeToTopic(topic)
LogEx.logDebug(TAG, "topic=${topic}") LogEx.logDebug(TAG, "topic=${topic}")
InstallHelps.init()
NewComUtils.requestCfg { NewComUtils.requestCfg {
ScreenStatusReceiver.setupScreenStatusListener(this) ScreenStatusReceiver.setupScreenStatusListener(this)
val timerStatus: Int = AppPreferences.getInstance().getString("timerS", "1").toIntOrNull() ?: 1 val timerStatus: Int = AppPreferences.getInstance().getString("timerS", "1").toIntOrNull() ?: 1
...@@ -72,7 +73,6 @@ class MyApplication : BaseApplication() { ...@@ -72,7 +73,6 @@ class MyApplication : BaseApplication() {
} }
} }
if (ifAgreePrivacy) { if (ifAgreePrivacy) {
InstallHelps.init()
MobileAds.initialize(this) { initializationStatus -> MobileAds.initialize(this) { initializationStatus ->
} }
MainScope().launch(Dispatchers.Main) { MainScope().launch(Dispatchers.Main) {
......
...@@ -93,7 +93,7 @@ public class AdDisplayUtils { ...@@ -93,7 +93,7 @@ public class AdDisplayUtils {
} }
adRequestFailCount++; adRequestFailCount++;
saveAdRequestFailCount(); saveAdRequestFailCount();
Log.d("glc","广告请求失败:"+adRequestFailCount); Log.d("glc", "广告请求失败:" + adRequestFailCount);
} }
...@@ -106,7 +106,7 @@ public class AdDisplayUtils { ...@@ -106,7 +106,7 @@ public class AdDisplayUtils {
saveAdClickCount(); saveAdClickCount();
} }
private String getCurrentDate() { public String getCurrentDate() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
Date currentDate = Calendar.getInstance().getTime(); Date currentDate = Calendar.getInstance().getTime();
return dateFormat.format(currentDate); return dateFormat.format(currentDate);
......
...@@ -15,6 +15,7 @@ import androidx.core.graphics.drawable.IconCompat ...@@ -15,6 +15,7 @@ import androidx.core.graphics.drawable.IconCompat
import com.base.datarecovery.MyApplication import com.base.datarecovery.MyApplication
import com.base.datarecovery.R import com.base.datarecovery.R
import com.base.datarecovery.activity.SplashActivity import com.base.datarecovery.activity.SplashActivity
import com.base.datarecovery.ads.AdDisplayUtils
import com.base.datarecovery.bean.ConstObject.ID_JUNK_CLEAN_PUSH import com.base.datarecovery.bean.ConstObject.ID_JUNK_CLEAN_PUSH
import com.base.datarecovery.bean.ConstObject.ID_PRIVACY_SPACE import com.base.datarecovery.bean.ConstObject.ID_PRIVACY_SPACE
import com.base.datarecovery.bean.ConstObject.ID_RECOVERY_DOCUMENTS import com.base.datarecovery.bean.ConstObject.ID_RECOVERY_DOCUMENTS
...@@ -101,13 +102,17 @@ object NotificationUtil { ...@@ -101,13 +102,17 @@ object NotificationUtil {
smallRemoteViews.setTextViewText(R.id.tv_btn, btn) smallRemoteViews.setTextViewText(R.id.tv_btn, btn)
//取消按钮 //取消按钮
bigRemoteViews.setOnClickPendingIntent(R.id.fl_cancel, cancelNotificationPendingIntent(context, actionId)) bigRemoteViews.setOnClickPendingIntent(
R.id.fl_cancel,
cancelNotificationPendingIntent(context, actionId)
)
//跳转 //跳转
val intent = Intent(context, SplashActivity::class.java) val intent = Intent(context, SplashActivity::class.java)
intent.putExtra("actionId", actionId) intent.putExtra("actionId", actionId)
val btnRequestCode = Random().nextInt(1000) val btnRequestCode = Random().nextInt(1000)
val btnPendingIntent = PendingIntent.getActivity(context, btnRequestCode, intent, PendingIntent.FLAG_IMMUTABLE) val btnPendingIntent =
PendingIntent.getActivity(context, btnRequestCode, intent, PendingIntent.FLAG_IMMUTABLE)
bigRemoteViews.setOnClickPendingIntent(R.id.fl_btn, btnPendingIntent) bigRemoteViews.setOnClickPendingIntent(R.id.fl_btn, btnPendingIntent)
smallRemoteViews.setOnClickPendingIntent(R.id.tv_btn, btnPendingIntent) smallRemoteViews.setOnClickPendingIntent(R.id.tv_btn, btnPendingIntent)
...@@ -121,7 +126,12 @@ object NotificationUtil { ...@@ -121,7 +126,12 @@ object NotificationUtil {
cancelIntent.setAction(CloseNotificationReceiver.Action) cancelIntent.setAction(CloseNotificationReceiver.Action)
cancelIntent.putExtra(CloseNotificationReceiver.NotificationId, actionId) cancelIntent.putExtra(CloseNotificationReceiver.NotificationId, actionId)
val broadcastRequestCode = Random().nextInt(1000) val broadcastRequestCode = Random().nextInt(1000)
return PendingIntent.getBroadcast(context, broadcastRequestCode, cancelIntent, PendingIntent.FLAG_IMMUTABLE) return PendingIntent.getBroadcast(
context,
broadcastRequestCode,
cancelIntent,
PendingIntent.FLAG_IMMUTABLE
)
} }
...@@ -133,7 +143,8 @@ object NotificationUtil { ...@@ -133,7 +143,8 @@ object NotificationUtil {
smallRemoteViews: RemoteViews smallRemoteViews: RemoteViews
) { ) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
//创建channel //创建channel
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
...@@ -163,7 +174,8 @@ object NotificationUtil { ...@@ -163,7 +174,8 @@ object NotificationUtil {
.setContentText("notification") .setContentText("notification")
val requestCode = kotlin.random.Random.nextInt(1000) val requestCode = kotlin.random.Random.nextInt(1000)
val pendingIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE) val pendingIntent =
PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE)
builder.setContentIntent(pendingIntent) builder.setContentIntent(pendingIntent)
.setDeleteIntent(cancelNotificationPendingIntent(context, actionId)) .setDeleteIntent(cancelNotificationPendingIntent(context, actionId))
.setPriority(NotificationCompat.PRIORITY_MAX) .setPriority(NotificationCompat.PRIORITY_MAX)
...@@ -186,6 +198,7 @@ object NotificationUtil { ...@@ -186,6 +198,7 @@ object NotificationUtil {
} else { } else {
notificationManager.notify(actionId, builder.build()) notificationManager.notify(actionId, builder.build())
} }
incrementNotification()
AppPreferences.getInstance().put("last_notification_time", System.currentTimeMillis()) AppPreferences.getInstance().put("last_notification_time", System.currentTimeMillis())
} }
...@@ -193,7 +206,20 @@ object NotificationUtil { ...@@ -193,7 +206,20 @@ object NotificationUtil {
private var handlerThread: HandlerThread? = null private var handlerThread: HandlerThread? = null
private var handler: Handler? = null private var handler: Handler? = null
private fun incrementNotification() {
val key = "showNotificationCount_" + AdDisplayUtils.getInstance().getCurrentDate()
var s = AppPreferences.getInstance().getInt(key, 0)
s++
AppPreferences.getInstance().put(key, s)
}
fun sendNotification(context: Context) { fun sendNotification(context: Context) {
val currentNum = AppPreferences.getInstance().getInt("showNotificationCount_" + AdDisplayUtils.getInstance().getCurrentDate(), 0)
val maxNum = AppPreferences.getInstance().getInt("maxShowNotificationCount", 100)
if (currentNum >= maxNum) {
return
}
val actionId: Int = getNextNotificationId() val actionId: Int = getNextNotificationId()
EventUtils.event("showNotification", null, null, false) EventUtils.event("showNotification", null, null, false)
...@@ -201,7 +227,8 @@ object NotificationUtil { ...@@ -201,7 +227,8 @@ object NotificationUtil {
return return
} }
val interval: Int = AppPreferences.getInstance().getString("notificationInterval", "60").toIntOrNull() ?: 60 val interval: Int =
AppPreferences.getInstance().getString("notificationInterval", "60").toIntOrNull() ?: 60
val lastTime: Long = AppPreferences.getInstance().getLong("last_notification_time", 0) val lastTime: Long = AppPreferences.getInstance().getLong("last_notification_time", 0)
val nowTime = System.currentTimeMillis() val nowTime = System.currentTimeMillis()
val x = nowTime - lastTime val x = nowTime - lastTime
...@@ -215,7 +242,8 @@ object NotificationUtil { ...@@ -215,7 +242,8 @@ object NotificationUtil {
if (open == 1) { if (open == 1) {
val num: Int = AppPreferences.getInstance().getString("num", "0").toIntOrNull() ?: 0 val num: Int = AppPreferences.getInstance().getString("num", "0").toIntOrNull() ?: 0
val delay: Long = AppPreferences.getInstance().getString("delay", "0").toLongOrNull() ?: 0L val delay: Long =
AppPreferences.getInstance().getString("delay", "0").toLongOrNull() ?: 0L
handlerThread = HandlerThread("NotificationHandlerThread") handlerThread = HandlerThread("NotificationHandlerThread")
handlerThread!!.start() handlerThread!!.start()
......
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