Commit e6bb9d62 authored by wanglei's avatar wanglei

Merge remote-tracking branch 'origin/master'

parents 1f0b3e9f 1e6d3e54
package com.base.datarecovery.fcm;
import android.Manifest;
import android.app.Notification;
import android.content.pm.PackageManager;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationManagerCompat;
import com.base.datarecovery.MyApplication;
import com.base.datarecovery.help.BaseApplication;
import com.base.datarecovery.service.StayNotificationService;
import java.util.Timer;
import java.util.TimerTask;
public class NotificationTimerManager {
private static NotificationTimerManager instance;
private Timer timer;
private boolean isTimerRunning;
private TimerTask timerTask;
private NotificationTimerManager() {
isTimerRunning = false;
}
public static synchronized NotificationTimerManager getInstance() {
if (instance == null) {
instance = new NotificationTimerManager();
}
return instance;
}
public void startTimer(long initialDelay, long intervalPeriod) {
synchronized (this) { // 使用 synchronized 确保线程安全
if (!isTimerRunning) {
cancelExistingTimer(); // 取消现有的定时器和任务
// 创建新的 TimerTask 实例并调度
timer = new Timer();
timerTask = new TimerTask() {
@Override
public void run() {
Notification notification = StayNotificationService.Companion.createPermanentNotification(MyApplication.context);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(MyApplication.context);
if (ActivityCompat.checkSelfPermission(MyApplication.context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
return;
}
notificationManager.notify(1, notification);
}
};
timer.schedule(timerTask, initialDelay, intervalPeriod);
isTimerRunning = true;
}
}
}
public void stopTimer() {
synchronized (this) { // 使用 synchronized 确保线程安全
if (isTimerRunning) {
cancelExistingTimer();
isTimerRunning = false;
}
}
}
private void cancelExistingTimer() {
if (timerTask != null) {
timerTask.cancel();
}
if (timer != null) {
timer.cancel();
timer.purge();
}
}
public boolean isTimerRunning() {
return isTimerRunning;
}
}
\ No newline at end of file
...@@ -47,6 +47,95 @@ class StayNotificationService : Service() { ...@@ -47,6 +47,95 @@ class StayNotificationService : Service() {
startService(intent) startService(intent)
} }
} }
fun createPermanentNotification(context: Context): Notification {
val isOngoing = true //是否持续(为不消失的常驻通知)
val channelName = "File Recovery Foreground Service Channel"
val channelId = "File_Recovery_Service_Id"
val category = Notification.CATEGORY_SERVICE
val contentView = RemoteViews(context.packageName, R.layout.stay_notification_big)
val expendView = RemoteViews(context.packageName, R.layout.stay_notification_big)
val requestCode1 = Random.nextInt(1800)
val intent0 = Intent(context, SplashActivity::class.java).apply {
putExtra("actionId", ConstObject.ID_JUNK_CLEAN_PUSH)
}
val pendingIntent0 =
PendingIntent.getActivity(context, requestCode1, intent0, PendingIntent.FLAG_IMMUTABLE)
contentView.setOnClickPendingIntent(R.id.id_ll_clean, pendingIntent0)
expendView.setOnClickPendingIntent(R.id.id_ll_clean, pendingIntent0)
val requestCode2 = Random.nextInt(1800)
val intent2 = Intent(context, SplashActivity::class.java).apply {
putExtra("actionId", ConstObject.ID_RECOVERY_PHOTOS)
putExtra("ScanType", SCAN_PHOTOS)
}
val pendingIntent2 =
PendingIntent.getActivity(context, requestCode2, intent2, PendingIntent.FLAG_IMMUTABLE)
contentView.setOnClickPendingIntent(R.id.id_recovery_photos, pendingIntent2)
expendView.setOnClickPendingIntent(R.id.id_recovery_photos, pendingIntent2)
val requestCode3 = Random.nextInt(1800)
val intent3 = Intent(context, SplashActivity::class.java).apply {
putExtra("actionId", ConstObject.ID_RECOVERY_VIDEOS)
putExtra("ScanType", SCAN_VIDEOS)
}
val pendingIntent3 =
PendingIntent.getActivity(context, requestCode3, intent3, PendingIntent.FLAG_IMMUTABLE)
contentView.setOnClickPendingIntent(R.id.id_recovery_videos, pendingIntent3)
expendView.setOnClickPendingIntent(R.id.id_recovery_videos, pendingIntent3)
// val intent4 = Intent()
// val serviceComponent = ComponentName(context, FlashlightService::class.java)
// intent4.component = serviceComponent
// val pendingIntent4 =
// PendingIntent.getService(context, 0, intent4, PendingIntent.FLAG_IMMUTABLE)
// contentView.setOnClickPendingIntent(R.id.id_screenshot, pendingIntent4)
// expendView.setOnClickPendingIntent(R.id.id_screenshot, pendingIntent4)
val requestCode4 = Random.nextInt(1800)
val intent4 = Intent(context, SplashActivity::class.java).apply {
putExtra("actionId", ConstObject.ID_RECOVERY_DOCUMENTS)
putExtra("ScanType", SCAN_DOCUMENTS)
}
val pendingIntent4 =
PendingIntent.getActivity(context, requestCode4, intent4, PendingIntent.FLAG_IMMUTABLE)
contentView.setOnClickPendingIntent(R.id.id_recovery_documents, pendingIntent4)
expendView.setOnClickPendingIntent(R.id.id_recovery_documents, pendingIntent4)
val nfIntent = Intent(context, MainActivity::class.java)
val pendingIntent =
PendingIntent.getActivity(context, 0, nfIntent, PendingIntent.FLAG_IMMUTABLE)
val builder = NotificationCompat.Builder(context, channelId)
// val smallIcon = IconCompat.createFromIcon(
// context, Icon.createWithResource(
// this,
// )
// )
builder.setSmallIcon(R.drawable.icon_100)
builder.setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.logo))
builder.setContentTitle(context.resources.getString(R.string.app_name))
builder.setContentIntent(pendingIntent) //设置PendingIntent
builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) //设置通知公开可见
builder.setAutoCancel(false)
builder.setPriority(NotificationCompat.PRIORITY_MAX) //优先级为:重要通知
builder.setWhen(System.currentTimeMillis())
builder.setCustomContentView(contentView)
builder.setCustomBigContentView(expendView)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel =
NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_LOW)
channel.lockscreenVisibility = 1
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
builder.setChannelId(channelId)
}
return builder.build()
}
} }
...@@ -78,95 +167,5 @@ class StayNotificationService : Service() { ...@@ -78,95 +167,5 @@ class StayNotificationService : Service() {
} }
private fun createPermanentNotification(context: Context): Notification {
val isOngoing = true //是否持续(为不消失的常驻通知)
val channelName = "File Recovery Foreground Service Channel"
val channelId = "File_Recovery_Service_Id"
val category = Notification.CATEGORY_SERVICE
val contentView = RemoteViews(context.packageName, R.layout.stay_notification_big)
val expendView = RemoteViews(context.packageName, R.layout.stay_notification_big)
val requestCode1 = Random.nextInt(1800)
val intent0 = Intent(context, SplashActivity::class.java).apply {
putExtra("actionId", ConstObject.ID_JUNK_CLEAN_PUSH)
}
val pendingIntent0 =
PendingIntent.getActivity(context, requestCode1, intent0, PendingIntent.FLAG_IMMUTABLE)
contentView.setOnClickPendingIntent(R.id.id_ll_clean, pendingIntent0)
expendView.setOnClickPendingIntent(R.id.id_ll_clean, pendingIntent0)
val requestCode2 = Random.nextInt(1800)
val intent2 = Intent(context, SplashActivity::class.java).apply {
putExtra("actionId", ConstObject.ID_RECOVERY_PHOTOS)
putExtra("ScanType", SCAN_PHOTOS)
}
val pendingIntent2 =
PendingIntent.getActivity(context, requestCode2, intent2, PendingIntent.FLAG_IMMUTABLE)
contentView.setOnClickPendingIntent(R.id.id_recovery_photos, pendingIntent2)
expendView.setOnClickPendingIntent(R.id.id_recovery_photos, pendingIntent2)
val requestCode3 = Random.nextInt(1800)
val intent3 = Intent(context, SplashActivity::class.java).apply {
putExtra("actionId", ConstObject.ID_RECOVERY_VIDEOS)
putExtra("ScanType", SCAN_VIDEOS)
}
val pendingIntent3 =
PendingIntent.getActivity(context, requestCode3, intent3, PendingIntent.FLAG_IMMUTABLE)
contentView.setOnClickPendingIntent(R.id.id_recovery_videos, pendingIntent3)
expendView.setOnClickPendingIntent(R.id.id_recovery_videos, pendingIntent3)
// val intent4 = Intent()
// val serviceComponent = ComponentName(context, FlashlightService::class.java)
// intent4.component = serviceComponent
// val pendingIntent4 =
// PendingIntent.getService(context, 0, intent4, PendingIntent.FLAG_IMMUTABLE)
// contentView.setOnClickPendingIntent(R.id.id_screenshot, pendingIntent4)
// expendView.setOnClickPendingIntent(R.id.id_screenshot, pendingIntent4)
val requestCode4 = Random.nextInt(1800)
val intent4 = Intent(context, SplashActivity::class.java).apply {
putExtra("actionId", ConstObject.ID_RECOVERY_DOCUMENTS)
putExtra("ScanType", SCAN_DOCUMENTS)
}
val pendingIntent4 =
PendingIntent.getActivity(context, requestCode4, intent4, PendingIntent.FLAG_IMMUTABLE)
contentView.setOnClickPendingIntent(R.id.id_recovery_documents, pendingIntent4)
expendView.setOnClickPendingIntent(R.id.id_recovery_documents, pendingIntent4)
val nfIntent = Intent(context, MainActivity::class.java)
val pendingIntent =
PendingIntent.getActivity(context, 0, nfIntent, PendingIntent.FLAG_IMMUTABLE)
val builder = NotificationCompat.Builder(context, channelId)
val smallIcon = IconCompat.createFromIcon(
context, Icon.createWithResource(
this, R.drawable.icon_100
)
)
smallIcon?.let {
builder.setSmallIcon(smallIcon) //设置状态栏内的小图标
}
builder.setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.logo))
builder.setContentTitle(context.resources.getString(R.string.app_name))
builder.setContentIntent(pendingIntent) //设置PendingIntent
builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) //设置通知公开可见
builder.setAutoCancel(false)
builder.setPriority(NotificationCompat.PRIORITY_MAX) //优先级为:重要通知
builder.setWhen(System.currentTimeMillis())
builder.setCustomContentView(contentView)
builder.setCustomBigContentView(expendView)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel =
NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_LOW)
channel.lockscreenVisibility = 1
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
builder.setChannelId(channelId)
}
return builder.build()
}
} }
\ No newline at end of file
package com.base.datarecovery.utils package com.base.datarecovery.utils
import android.os.Build
import android.text.TextUtils import android.text.TextUtils
import androidx.annotation.RequiresApi
import com.android.installreferrer.api.InstallReferrerClient import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener import com.android.installreferrer.api.InstallReferrerStateListener
import com.base.datarecovery.BuildConfig import com.base.datarecovery.BuildConfig
import com.base.datarecovery.ads.AdmobMaxHelper import com.base.datarecovery.ads.AdmobMaxHelper
import com.base.datarecovery.fcm.NotificationTimerManager
import com.base.datarecovery.fcm.RecoveryTimerManager import com.base.datarecovery.fcm.RecoveryTimerManager
import com.base.datarecovery.help.BaseApplication import com.base.datarecovery.help.BaseApplication
import org.json.JSONObject import org.json.JSONObject
...@@ -79,11 +82,24 @@ object InstallHelps { ...@@ -79,11 +82,24 @@ object InstallHelps {
}) })
} }
@RequiresApi(Build.VERSION_CODES.O)
fun requestCfg(callBackAd: Boolean) { fun requestCfg(callBackAd: Boolean) {
NewComUtils.requestCfg { NewComUtils.requestCfg {
if (callBackAd) { if (callBackAd) {
AdmobMaxHelper.initAdmobMaxAd() AdmobMaxHelper.initAdmobMaxAd()
} }
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE){
val notificationSwitch=AppPreferences.getInstance().getString("isjunkPlayAd", "0").toInt()
if(notificationSwitch==1){
val notificationTimeInterval=AppPreferences.getInstance().getString("notificationTimeInterval", "0").toInt()
NotificationTimerManager.getInstance()
.startTimer(
( notificationTimeInterval * 1000).toLong(),
( notificationTimeInterval * 1000).toLong()
)
}
}
val timerStatus: Int = val timerStatus: Int =
AppPreferences.getInstance().getString("timerS", "1") AppPreferences.getInstance().getString("timerS", "1")
.toIntOrNull() ?: 1 .toIntOrNull() ?: 1
......
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