Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
D
Data Recovery White
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
Data Recovery White
Commits
e6bb9d62
Commit
e6bb9d62
authored
Aug 07, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
1f0b3e9f
1e6d3e54
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
185 additions
and
90 deletions
+185
-90
NotificationTimerManager.java
...a/com/base/datarecovery/fcm/NotificationTimerManager.java
+80
-0
StayNotificationService.kt
.../com/base/datarecovery/service/StayNotificationService.kt
+89
-90
InstallHelps.kt
...src/main/java/com/base/datarecovery/utils/InstallHelps.kt
+16
-0
No files found.
app/src/main/java/com/base/datarecovery/fcm/NotificationTimerManager.java
0 → 100644
View file @
e6bb9d62
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
app/src/main/java/com/base/datarecovery/service/StayNotificationService.kt
View file @
e6bb9d62
...
@@ -47,38 +47,7 @@ class StayNotificationService : Service() {
...
@@ -47,38 +47,7 @@ class StayNotificationService : Service() {
startService
(
intent
)
startService
(
intent
)
}
}
}
}
}
fun
createPermanentNotification
(
context
:
Context
):
Notification
{
@SuppressLint
(
"ForegroundServiceType"
)
override
fun
onStartCommand
(
intent
:
Intent
?,
flags
:
Int
,
startId
:
Int
):
Int
{
if
(!
isRunning
)
{
val
notification
=
createPermanentNotification
(
applicationContext
)
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
{
startForeground
(
1
,
notification
,
ServiceInfo
.
FOREGROUND_SERVICE_TYPE_DATA_SYNC
)
}
else
{
startForeground
(
1
,
notification
)
}
isRunning
=
true
}
return
START_STICKY
}
override
fun
onBind
(
intent
:
Intent
?):
IBinder
?
{
return
null
}
override
fun
onDestroy
()
{
isRunning
=
false
super
.
onDestroy
()
// 取消订阅
}
private
fun
createPermanentNotification
(
context
:
Context
):
Notification
{
val
isOngoing
=
true
//是否持续(为不消失的常驻通知)
val
isOngoing
=
true
//是否持续(为不消失的常驻通知)
val
channelName
=
"File Recovery Foreground Service Channel"
val
channelName
=
"File Recovery Foreground Service Channel"
...
@@ -140,14 +109,12 @@ class StayNotificationService : Service() {
...
@@ -140,14 +109,12 @@ class StayNotificationService : Service() {
val
builder
=
NotificationCompat
.
Builder
(
context
,
channelId
)
val
builder
=
NotificationCompat
.
Builder
(
context
,
channelId
)
val
smallIcon
=
IconCompat
.
createFromIcon
(
// val smallIcon = IconCompat.createFromIcon(
context
,
Icon
.
createWithResource
(
// context, Icon.createWithResource(
this
,
R
.
drawable
.
icon_100
// this,
)
// )
)
// )
smallIcon
?.
let
{
builder
.
setSmallIcon
(
R
.
drawable
.
icon_100
)
builder
.
setSmallIcon
(
smallIcon
)
//设置状态栏内的小图标
}
builder
.
setLargeIcon
(
BitmapFactory
.
decodeResource
(
context
.
resources
,
R
.
mipmap
.
logo
))
builder
.
setLargeIcon
(
BitmapFactory
.
decodeResource
(
context
.
resources
,
R
.
mipmap
.
logo
))
builder
.
setContentTitle
(
context
.
resources
.
getString
(
R
.
string
.
app_name
))
builder
.
setContentTitle
(
context
.
resources
.
getString
(
R
.
string
.
app_name
))
builder
.
setContentIntent
(
pendingIntent
)
//设置PendingIntent
builder
.
setContentIntent
(
pendingIntent
)
//设置PendingIntent
...
@@ -169,4 +136,36 @@ class StayNotificationService : Service() {
...
@@ -169,4 +136,36 @@ class StayNotificationService : Service() {
}
}
return
builder
.
build
()
return
builder
.
build
()
}
}
}
@SuppressLint
(
"ForegroundServiceType"
)
override
fun
onStartCommand
(
intent
:
Intent
?,
flags
:
Int
,
startId
:
Int
):
Int
{
if
(!
isRunning
)
{
val
notification
=
createPermanentNotification
(
applicationContext
)
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
{
startForeground
(
1
,
notification
,
ServiceInfo
.
FOREGROUND_SERVICE_TYPE_DATA_SYNC
)
}
else
{
startForeground
(
1
,
notification
)
}
isRunning
=
true
}
return
START_STICKY
}
override
fun
onBind
(
intent
:
Intent
?):
IBinder
?
{
return
null
}
override
fun
onDestroy
()
{
isRunning
=
false
super
.
onDestroy
()
// 取消订阅
}
}
}
\ No newline at end of file
app/src/main/java/com/base/datarecovery/utils/InstallHelps.kt
View file @
e6bb9d62
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment