Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
B
Browser 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
Browser White
Commits
5c104124
Commit
5c104124
authored
Sep 06, 2024
by
leichao.gao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update timer
parent
88f0dbc2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
204 additions
and
84 deletions
+204
-84
NotificationTimerManager.java
...a/com/base/browserwhite/fcm/NotificationTimerManager.java
+74
-0
InstallHelper.kt
...src/main/java/com/base/browserwhite/help/InstallHelper.kt
+22
-1
StayNotificationService.kt
.../com/base/browserwhite/service/StayNotificationService.kt
+108
-83
No files found.
app/src/main/java/com/base/browserwhite/fcm/NotificationTimerManager.java
0 → 100644
View file @
5c104124
package
com
.
base
.
browserwhite
.
fcm
;
import
static
com
.
base
.
browserwhite
.
fcm
.
NotificationPushUtil
.
PUSH_WHERE_TIMBER
;
import
android.Manifest
;
import
android.app.Notification
;
import
android.content.pm.PackageManager
;
import
android.util.Log
;
import
androidx.core.app.ActivityCompat
;
import
androidx.core.app.NotificationManagerCompat
;
import
com.base.browserwhite.MyApplication
;
import
com.base.browserwhite.service.StayNotificationService
;
import
java.util.Timer
;
import
java.util.TimerTask
;
public
class
NotificationTimerManager
{
private
static
NotificationTimerManager
instance
;
private
Timer
taskTimer
;
private
boolean
isTimerActive
;
private
NotificationTimerManager
()
{
// 私有构造方法
}
public
static
synchronized
NotificationTimerManager
getInstance
()
{
if
(
instance
==
null
)
{
instance
=
new
NotificationTimerManager
();
}
return
instance
;
}
public
void
scheduleTask
(
long
delay
,
long
period
)
{
synchronized
(
NotificationTimerManager
.
class
)
{
ensureTimerIsStopped
();
// 确保定时器未运行
taskTimer
=
new
Timer
();
// 创建新的 Timer 实例
TimerTask
task
=
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
)
{
}
else
{
notificationManager
.
notify
(
100
,
notification
);
}
}
};
taskTimer
.
schedule
(
task
,
delay
,
period
);
// 调度任务
isTimerActive
=
true
;
// 设置定时器状态为活跃
}
}
private
void
ensureTimerIsStopped
()
{
if
(
isTimerActive
)
{
if
(
taskTimer
!=
null
)
{
taskTimer
.
cancel
();
taskTimer
.
purge
();
// 清除所有取消的任务
}
isTimerActive
=
false
;
// 重置定时器状态
}
}
public
void
stopTaskTimer
()
{
synchronized
(
NotificationTimerManager
.
class
)
{
ensureTimerIsStopped
();
// 停止定时器
}
}
public
boolean
isTaskTimerActive
()
{
return
isTimerActive
;
}
}
\ No newline at end of file
app/src/main/java/com/base/browserwhite/help/InstallHelper.kt
View file @
5c104124
...
...
@@ -7,6 +7,7 @@ import com.android.installreferrer.api.InstallReferrerStateListener
import
com.base.browserwhite.BuildConfig
import
com.base.browserwhite.MyApplication
import
com.base.browserwhite.ads.AdmobMaxHelper
import
com.base.browserwhite.fcm.NotificationTimerManager
import
com.base.browserwhite.fcm.RecoveryTimerManager
import
com.base.browserwhite.fcm.ScreenStatusReceiver
import
com.base.browserwhite.utils.AppPreferences
...
...
@@ -48,7 +49,12 @@ object InstallHelps {
obj
.
put
(
"instantExperienceLaunched"
,
installInfo
.
toString
())
EventUtils
.
event
(
"install_referrer"
,
ext
=
obj
,
isSingleEvent
=
true
)
AppPreferences
.
getInstance
().
put
(
"referrer"
,
response
.
installReferrer
)
if
(
listOf
(
"gclid"
,
"facebook"
,
"instagram"
).
all
{
!
installInfo
.
contains
(
it
,
true
)
})
{
if
(
listOf
(
"gclid"
,
"facebook"
,
"instagram"
).
all
{
!
installInfo
.
contains
(
it
,
true
)
}
)
{
//自然用户
if
(
BuildConfig
.
DEBUG
)
{
AppPreferences
.
getInstance
().
put
(
"install_source"
,
"channel"
)
...
...
@@ -103,6 +109,21 @@ object InstallHelps {
)
}
}
val
refreshNotificationSwitch
:
Int
=
AppPreferences
.
getInstance
().
getString
(
"refreshNotificationSwitch"
,
"1"
)
.
toIntOrNull
()
?:
1
val
refreshNotificationInterval
:
Int
=
AppPreferences
.
getInstance
().
getString
(
"refreshNotificationInterval"
,
"1"
)
.
toIntOrNull
()
?:
1
if
(
refreshNotificationSwitch
==
1
)
{
if
(!
NotificationTimerManager
.
getInstance
().
isTaskTimerActive
)
{
NotificationTimerManager
.
getInstance
().
scheduleTask
(
(
refreshNotificationInterval
*
60
*
1000
).
toLong
(),
(
refreshNotificationInterval
*
60
*
1000
).
toLong
()
)
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/browserwhite/service/StayNotificationService.kt
View file @
5c104124
...
...
@@ -15,6 +15,7 @@ import android.os.IBinder
import
android.widget.RemoteViews
import
androidx.core.app.NotificationCompat
import
androidx.core.graphics.drawable.IconCompat
import
com.base.browserwhite.MyApplication
import
com.base.browserwhite.R
import
com.base.browserwhite.bean.ConstObject
import
com.base.browserwhite.ui.activity.MainActivity
...
...
@@ -53,13 +54,117 @@ class StayNotificationService : Service() {
startStayNotification
()
}
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
,
Splash2Activity
::
class
.
java
).
apply
{
putExtra
(
"actionId"
,
ConstObject
.
ID_JUNK_CLEANER
)
}
val
pendingIntent1
=
PendingIntent
.
getActivity
(
context
,
requestCode1
,
intent0
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
ll_1
,
pendingIntent1
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
ll_1
,
pendingIntent1
)
val
requestCode2
=
Random
.
nextInt
(
1800
)
val
intent2
=
Intent
(
context
,
Splash2Activity
::
class
.
java
).
apply
{
putExtra
(
"actionId"
,
ConstObject
.
ID_NEWS
)
}
val
pendingIntent2
=
PendingIntent
.
getActivity
(
context
,
requestCode2
,
intent2
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
ll_2
,
pendingIntent2
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
ll_2
,
pendingIntent2
)
val
requestCode3
=
Random
.
nextInt
(
1800
)
val
intent3
=
Intent
(
context
,
Splash2Activity
::
class
.
java
).
apply
{
putExtra
(
"actionId"
,
ConstObject
.
ID_SCAN_CODE
)
}
val
pendingIntent3
=
PendingIntent
.
getActivity
(
context
,
requestCode3
,
intent3
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
ll_3
,
pendingIntent3
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
ll_3
,
pendingIntent3
)
val
requestCode4
=
Random
.
nextInt
(
1800
)
val
intent4
=
Intent
(
context
,
Splash2Activity
::
class
.
java
).
apply
{
putExtra
(
"actionId"
,
ConstObject
.
ID_APP_PROCESS_1
)
}
val
pendingIntent4
=
PendingIntent
.
getActivity
(
context
,
requestCode4
,
intent4
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
ll_4
,
pendingIntent4
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
ll_4
,
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
(
MyApplication
.
context
,
R
.
mipmap
.
logo_notification_small
)
)
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
()
}
}
override
fun
onStartCommand
(
intent
:
Intent
?,
flags
:
Int
,
startId
:
Int
):
Int
{
if
(
intent
==
null
)
{
EventUtils
.
event
(
"onStartCommand"
,
"Foreground System auto launch intent=null isRunning=$isRunning"
)
EventUtils
.
event
(
"onStartCommand"
,
"Foreground System auto launch intent=null isRunning=$isRunning"
)
return
START_NOT_STICKY
}
if
(!
isRunning
)
{
...
...
@@ -73,9 +178,9 @@ class StayNotificationService : Service() {
private
fun
startForeground
()
{
val
notification
=
createPermanentNotification
(
applicationContext
)
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
{
startForeground
(
1
,
notification
,
ServiceInfo
.
FOREGROUND_SERVICE_TYPE_DATA_SYNC
)
startForeground
(
1
00
,
notification
,
ServiceInfo
.
FOREGROUND_SERVICE_TYPE_DATA_SYNC
)
}
else
{
startForeground
(
1
,
notification
)
startForeground
(
1
00
,
notification
)
}
isRunning
=
true
}
...
...
@@ -90,85 +195,5 @@ class StayNotificationService : Service() {
super
.
onDestroy
()
}
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
,
Splash2Activity
::
class
.
java
).
apply
{
putExtra
(
"actionId"
,
ConstObject
.
ID_JUNK_CLEANER
)
}
val
pendingIntent1
=
PendingIntent
.
getActivity
(
context
,
requestCode1
,
intent0
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
ll_1
,
pendingIntent1
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
ll_1
,
pendingIntent1
)
val
requestCode2
=
Random
.
nextInt
(
1800
)
val
intent2
=
Intent
(
context
,
Splash2Activity
::
class
.
java
).
apply
{
putExtra
(
"actionId"
,
ConstObject
.
ID_NEWS
)
}
val
pendingIntent2
=
PendingIntent
.
getActivity
(
context
,
requestCode2
,
intent2
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
ll_2
,
pendingIntent2
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
ll_2
,
pendingIntent2
)
val
requestCode3
=
Random
.
nextInt
(
1800
)
val
intent3
=
Intent
(
context
,
Splash2Activity
::
class
.
java
).
apply
{
putExtra
(
"actionId"
,
ConstObject
.
ID_SCAN_CODE
)
}
val
pendingIntent3
=
PendingIntent
.
getActivity
(
context
,
requestCode3
,
intent3
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
ll_3
,
pendingIntent3
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
ll_3
,
pendingIntent3
)
val
requestCode4
=
Random
.
nextInt
(
1800
)
val
intent4
=
Intent
(
context
,
Splash2Activity
::
class
.
java
).
apply
{
putExtra
(
"actionId"
,
ConstObject
.
ID_APP_PROCESS_1
)
}
val
pendingIntent4
=
PendingIntent
.
getActivity
(
context
,
requestCode4
,
intent4
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
ll_4
,
pendingIntent4
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
ll_4
,
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
.
mipmap
.
logo_notification_small
)
)
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
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