Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
E
Easy Cleaner Junk
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
Easy Cleaner Junk
Commits
58d76642
Commit
58d76642
authored
Jun 27, 2024
by
leichao.gao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持延长通知停留时间
parent
2b50c48c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
3 deletions
+67
-3
MyApplication.kt
.../main/java/com/test/easy/easycleanerjunk/MyApplication.kt
+1
-0
NewSplashActivity.kt
...easy/easycleanerjunk/activity/splash/NewSplashActivity.kt
+3
-0
CloseNotificationReceiver.java
...t/easy/easycleanerjunk/fcm/CloseNotificationReceiver.java
+1
-0
FcmService.java
...in/java/com/test/easy/easycleanerjunk/fcm/FcmService.java
+3
-0
NotificationUtil.java
...a/com/test/easy/easycleanerjunk/fcm/NotificationUtil.java
+59
-3
No files found.
app/src/main/java/com/test/easy/easycleanerjunk/MyApplication.kt
View file @
58d76642
...
...
@@ -24,6 +24,7 @@ import java.util.UUID
class
MyApplication
:
BaseApplication
()
{
companion
object
{
@JvmField
var
PAUSED_VALUE
=
0
}
...
...
app/src/main/java/com/test/easy/easycleanerjunk/activity/splash/NewSplashActivity.kt
View file @
58d76642
...
...
@@ -10,6 +10,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import
androidx.core.view.isVisible
import
com.test.easy.easycleanerjunk.databinding.ActivityLayoutSplashBinding
import
com.test.easy.easycleanerjunk.fcm.CloseNotificationReceiver
import
com.test.easy.easycleanerjunk.fcm.NotificationUtil
import
com.test.easy.easycleanerjunk.helps.BaseActivity
import
com.test.easy.easycleanerjunk.helps.ConfigHelper
import
com.test.easy.easycleanerjunk.helps.ads.AdmobUtils
...
...
@@ -47,6 +48,8 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
cancelIntent
.
action
=
CloseNotificationReceiver
.
action
cancelIntent
.
putExtra
(
CloseNotificationReceiver
.
id
,
jumpType
)
sendBroadcast
(
cancelIntent
)
}
else
{
NotificationUtil
.
stopNotificationHandler
()
}
mProgressManager
=
ProgressManager
(
binding
,
this
)
...
...
app/src/main/java/com/test/easy/easycleanerjunk/fcm/CloseNotificationReceiver.java
View file @
58d76642
...
...
@@ -14,6 +14,7 @@ public class CloseNotificationReceiver extends BroadcastReceiver {
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
NotificationUtil
.
stopNotificationHandler
();
if
(
action
!=
null
&&
action
.
equals
(
"CANCEL_NOTIFICATION"
))
{
int
notificationId
=
intent
.
getIntExtra
(
"NOTIFICATION_ID"
,
0
);
NotificationManager
notificationManager
=
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
...
...
app/src/main/java/com/test/easy/easycleanerjunk/fcm/FcmService.java
View file @
58d76642
...
...
@@ -21,6 +21,9 @@ public class FcmService extends FirebaseMessagingService {
int
lockS
=
remoteMessage
.
getData
().
get
(
"lockS"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"lockS"
))
:
0
;
SPUtils
.
getInstance
().
put
(
"actionS"
,
actionS
);
SPUtils
.
getInstance
().
put
(
"open"
,
open
);
SPUtils
.
getInstance
().
put
(
"num"
,
num
);
SPUtils
.
getInstance
().
put
(
"delay"
,
delay
);
NotificationUtil
.
sendNotification
(
MyApplication
.
context
);
...
...
app/src/main/java/com/test/easy/easycleanerjunk/fcm/NotificationUtil.java
View file @
58d76642
...
...
@@ -7,10 +7,13 @@ import android.app.PendingIntent;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.Build
;
import
android.os.Handler
;
import
android.os.HandlerThread
;
import
android.widget.RemoteViews
;
import
androidx.core.app.NotificationCompat
;
import
com.test.easy.easycleanerjunk.MyApplication
;
import
com.test.easy.easycleanerjunk.R
;
import
com.test.easy.easycleanerjunk.activity.splash.NewSplashActivity
;
import
com.test.easy.easycleanerjunk.bean.ConfigBean
;
...
...
@@ -41,12 +44,18 @@ public class NotificationUtil {
// Create an Intent for the activity you want to open when the notification is clicked
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
context
,
0
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
Intent
deleteIntent
=
new
Intent
(
context
,
CloseNotificationReceiver
.
class
);
deleteIntent
.
setAction
(
"DELETE_NOTIFICATION"
);
PendingIntent
deletePendingIntent
=
PendingIntent
.
getBroadcast
(
context
,
0
,
deleteIntent
,
PendingIntent
.
FLAG_MUTABLE
);
// Create the notification
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
context
,
"channel_id"
)
.
setSmallIcon
(
R
.
drawable
.
easycleanjunk_noticeicon
)
.
setContentTitle
(
"title"
)
.
setContentText
(
"message"
)
.
setContentIntent
(
pendingIntent
)
.
setDeleteIntent
(
deletePendingIntent
)
.
setPriority
(
NotificationCompat
.
PRIORITY_MAX
)
.
setContent
(
remoteViews
)
.
setCustomHeadsUpContentView
(
remoteViews
)
...
...
@@ -54,21 +63,68 @@ public class NotificationUtil {
.
setCustomContentView
(
remoteViews
)
.
setAutoCancel
(
true
);
// Show the notification
if
(
SPUtils
.
getInstance
().
getInt
(
"actionS"
,
0
)
==
1
)
{
notificationManager
.
notify
(
intent
.
getIntExtra
(
"actionId"
,
0
),
builder
.
build
());
if
(
SPUtils
.
getInstance
().
getInt
(
"actionS"
,
0
)
==
1
)
{
notificationManager
.
notify
(
intent
.
getIntExtra
(
"actionId"
,
0
),
builder
.
build
());
}
else
{
notificationManager
.
notify
(
0
,
builder
.
build
());
}
}
private
static
HandlerThread
handlerThread
;
private
static
Handler
handler
;
public
static
void
sendNotification
(
Context
context
)
{
int
actionId
=
getNextNotificationId
();
sendNotification
(
context
,
actionId
);
int
open
=
SPUtils
.
getInstance
().
getInt
(
"open"
,
0
);
int
num
=
SPUtils
.
getInstance
().
getInt
(
"num"
,
0
);
long
delay
=
SPUtils
.
getInstance
().
getLong
(
"delay"
,
0
);
if
(
open
==
1
)
{
handlerThread
=
new
HandlerThread
(
"NotificationHandlerThread"
);
handlerThread
.
start
();
// 创建 Handler
handler
=
new
Handler
(
handlerThread
.
getLooper
());
for
(
int
i
=
1
;
i
<=
num
;
i
++)
{
final
long
time
=
i
*
delay
;
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
MyApplication
.
PAUSED_VALUE
==
1
)
{
handler
.
removeCallbacksAndMessages
(
null
);
return
;
}
if
(
MyApplication
.
PAUSED_VALUE
!=
1
)
{
sendNotification
(
context
,
actionId
);
}
}
},
time
);
}
}
}
public
static
void
stopNotificationHandler
()
{
// 停止 HandlerThread
if
(
handler
!=
null
)
{
handler
.
removeCallbacksAndMessages
(
null
);
}
if
(
handlerThread
!=
null
)
{
handlerThread
.
quit
();
handlerThread
=
null
;
}
handler
=
null
;
}
public
static
void
sendNotification
(
Context
context
,
int
actionId
)
{
RemoteViews
remoteViews
=
new
RemoteViews
(
context
.
getPackageName
(),
R
.
layout
.
notification_common_notify
);
//功能触发push actionId 主动发送
String
desc
;
String
btn
;
int
icon
;
int
actionId
=
getNextNotificationId
();
if
(
actionId
==
ConfigBean
.
ID_JUNK_CLEAN_PUSH
)
{
icon
=
R
.
drawable
.
cleanjunk
;
desc
=
"Clean up remaining junk files"
;
...
...
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