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
2b50c48c
Commit
2b50c48c
authored
Jun 27, 2024
by
leichao.gao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FCM推送
parent
b1cf2cb3
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
391 additions
and
29 deletions
+391
-29
build.gradle
app/build.gradle
+1
-1
google-services.json
app/google-services.json
+5
-5
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+33
-0
MyApplication.kt
.../main/java/com/test/easy/easycleanerjunk/MyApplication.kt
+7
-4
DeviceScanActivity.kt
.../test/easy/easycleanerjunk/activity/DeviceScanActivity.kt
+12
-11
NewSplashActivity.kt
...easy/easycleanerjunk/activity/splash/NewSplashActivity.kt
+10
-4
SplashJumpUtils.kt
...t/easy/easycleanerjunk/activity/splash/SplashJumpUtils.kt
+4
-1
DeviceScanAdapter.kt
...om/test/easy/easycleanerjunk/adapter/DeviceScanAdapter.kt
+3
-1
ActionBroadcast.java
...va/com/test/easy/easycleanerjunk/fcm/ActionBroadcast.java
+51
-0
CloseNotificationReceiver.java
...t/easy/easycleanerjunk/fcm/CloseNotificationReceiver.java
+28
-0
FCMUtil.java
.../main/java/com/test/easy/easycleanerjunk/fcm/FCMUtil.java
+48
-0
FcmReceiver.java
...n/java/com/test/easy/easycleanerjunk/fcm/FcmReceiver.java
+14
-0
FcmService.java
...in/java/com/test/easy/easycleanerjunk/fcm/FcmService.java
+30
-0
NotificationUtil.java
...a/com/test/easy/easycleanerjunk/fcm/NotificationUtil.java
+141
-0
easycleanjunk_noticeicon.png
...src/main/res/drawable-xxhdpi/easycleanjunk_noticeicon.png
+0
-0
activity_device_scan.xml
app/src/main/res/layout/activity_device_scan.xml
+4
-0
notification_common_notify.xml
app/src/main/res/layout/notification_common_notify.xml
+0
-2
No files found.
app/build.gradle
View file @
2b50c48c
...
@@ -103,9 +103,9 @@ dependencies {
...
@@ -103,9 +103,9 @@ dependencies {
// implementation("androidx.room:room-ktx:$roomVersion")
// implementation("androidx.room:room-ktx:$roomVersion")
implementation
group:
'com.google.code.gson'
,
name:
'gson'
,
version:
'2.10.1'
implementation
group:
'com.google.code.gson'
,
name:
'gson'
,
version:
'2.10.1'
// implementation 'com.belerweb:pinyin4j:2.5.1'
// implementation 'com.belerweb:pinyin4j:2.5.1'
implementation
(
"com.google.firebase:firebase-messaging"
)
implementation
(
"com.google.firebase:firebase-messaging"
)
implementation
(
"com.facebook.android:facebook-android-sdk:[8,9)"
)
implementation
(
"com.facebook.android:facebook-android-sdk:[8,9)"
)
implementation
'com.makeramen:roundedimageview:2.3.0'
implementation
'com.makeramen:roundedimageview:2.3.0'
...
...
app/google-services.json
View file @
2b50c48c
{
{
"project_info"
:
{
"project_info"
:
{
"project_number"
:
"
993178188325
"
,
"project_number"
:
"
1032027169037
"
,
"project_id"
:
"
testcleanmaster
"
,
"project_id"
:
"
easycleanerjunk
"
,
"storage_bucket"
:
"
testcleanmaster
.appspot.com"
"storage_bucket"
:
"
easycleanerjunk
.appspot.com"
},
},
"client"
:
[
"client"
:
[
{
{
"client_info"
:
{
"client_info"
:
{
"mobilesdk_app_id"
:
"1:
993178188325:android:a7986c2607f23024825dcc
"
,
"mobilesdk_app_id"
:
"1:
1032027169037:android:c81c9c37c0534a2b2a9044
"
,
"android_client_info"
:
{
"android_client_info"
:
{
"package_name"
:
"com.test.easy.easycleanerjunk"
"package_name"
:
"com.test.easy.easycleanerjunk"
}
}
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
"oauth_client"
:
[],
"oauth_client"
:
[],
"api_key"
:
[
"api_key"
:
[
{
{
"current_key"
:
"AIzaSyC
Y5uqNx8qS5ZPvSIknbh2nH2v5vjzCmPI
"
"current_key"
:
"AIzaSyC
qV4IqJ0QYV7TCMBMBEPepvP0JD6Lj_5k
"
}
}
],
],
"services"
:
{
"services"
:
{
...
...
app/src/main/AndroidManifest.xml
View file @
2b50c48c
...
@@ -8,6 +8,13 @@
...
@@ -8,6 +8,13 @@
<uses-permission
android:name=
"android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.MANAGE_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.MANAGE_EXTERNAL_STORAGE"
/>
<!-- fcm 添加以下权限 -->
<uses-permission
android:name=
"android.permission.WAKE_LOCK"
/>
<uses-permission
android:name=
"com.google.android.c2dm.permission.RECEIVE"
/>
<uses-permission
android:name=
"android.permission.RECEIVE_BOOT_COMPLETED"
/>
<uses-permission
android:name=
"android.permission.POST_NOTIFICATIONS"
/>
<uses-permission
android:name=
"android.permission.FOREGROUND_SERVICE"
/>
<application
<application
android:name=
".MyApplication"
android:name=
".MyApplication"
android:allowBackup=
"true"
android:allowBackup=
"true"
...
@@ -141,6 +148,32 @@
...
@@ -141,6 +148,32 @@
<meta-data
<meta-data
android:name=
"com.facebook.sdk.ApplicationId"
android:name=
"com.facebook.sdk.ApplicationId"
android:value=
"@string/facebook_app_id"
/>
android:value=
"@string/facebook_app_id"
/>
<service
android:name=
".fcm.FcmService"
android:exported=
"true"
>
<intent-filter>
<action
android:name=
"com.google.firebase.MESSAGING_EVENT"
/>
</intent-filter>
</service>
<!-- 添加以下接收器 -->
<!-- 注册广播 -->
<receiver
android:name=
".fcm.FcmReceiver"
android:exported=
"true"
android:permission=
"com.google.android.c2dm.permission.SEND"
>
<intent-filter>
<action
android:name=
"com.google.firebase.MESSAGING_EVENT"
/>
<action
android:name=
"com.google.android.c2dm.intent.RECEIVE"
/>
<category
android:name=
"com.test.easy.cleanerjunk"
/>
</intent-filter>
</receiver>
<receiver
android:name=
".fcm.CloseNotificationReceiver"
android:exported=
"false"
>
<intent-filter>
<action
android:name=
"CANCEL_NOTIFICATION"
/>
</intent-filter>
</receiver>
</application>
</application>
...
...
app/src/main/java/com/test/easy/easycleanerjunk/MyApplication.kt
View file @
2b50c48c
...
@@ -5,9 +5,13 @@ import android.app.Activity
...
@@ -5,9 +5,13 @@ import android.app.Activity
import
android.content.Intent
import
android.content.Intent
import
android.os.Bundle
import
android.os.Bundle
import
android.text.TextUtils
import
android.text.TextUtils
import
android.util.Log
import
com.google.android.gms.ads.MobileAds
import
com.google.android.gms.ads.MobileAds
import
com.google.firebase.FirebaseApp
import
com.google.firebase.FirebaseApp
import
com.google.firebase.messaging.FirebaseMessaging
import
com.test.easy.easycleanerjunk.activity.splash.NewSplashActivity
import
com.test.easy.easycleanerjunk.activity.splash.NewSplashActivity
import
com.test.easy.easycleanerjunk.fcm.ActionBroadcast
import
com.test.easy.easycleanerjunk.fcm.FCMUtil
import
com.test.easy.easycleanerjunk.helps.BaseApplication
import
com.test.easy.easycleanerjunk.helps.BaseApplication
import
com.test.easy.easycleanerjunk.helps.ConfigHelper
import
com.test.easy.easycleanerjunk.helps.ConfigHelper
import
com.test.easy.easycleanerjunk.helps.ads.AdmobUtils
import
com.test.easy.easycleanerjunk.helps.ads.AdmobUtils
...
@@ -41,9 +45,6 @@ class MyApplication : BaseApplication() {
...
@@ -41,9 +45,6 @@ class MyApplication : BaseApplication() {
fun
initApp
()
{
fun
initApp
()
{
if
(
ConfigHelper
.
ifAgreePrivacy
)
{
if
(
ConfigHelper
.
ifAgreePrivacy
)
{
initNotificationWork
()
initNotificationWork
()
// MainScope().launch {
// InstallHelps.init()
// }
MobileAds
.
initialize
(
this
)
{
initializationStatus
->
MobileAds
.
initialize
(
this
)
{
initializationStatus
->
}
}
}
}
...
@@ -51,7 +52,9 @@ class MyApplication : BaseApplication() {
...
@@ -51,7 +52,9 @@ class MyApplication : BaseApplication() {
}
}
private
fun
initNotificationWork
()
{
private
fun
initNotificationWork
()
{
FirebaseApp
.
initializeApp
(
this
)
FCMUtil
.
initFirebase
(
this
)
FCMUtil
.
subscribeToTopic
(
"news"
)
ActionBroadcast
.
initBroadcast
(
this
)
}
}
@SuppressLint
(
"UnspecifiedRegisterReceiverFlag"
)
@SuppressLint
(
"UnspecifiedRegisterReceiverFlag"
)
...
...
app/src/main/java/com/test/easy/easycleanerjunk/activity/DeviceScanActivity.kt
View file @
2b50c48c
...
@@ -27,8 +27,17 @@ class DeviceScanActivity : BaseActivity<ActivityDeviceScanBinding>() {
...
@@ -27,8 +27,17 @@ class DeviceScanActivity : BaseActivity<ActivityDeviceScanBinding>() {
ConfigHelper
.
ifGuest
=
true
ConfigHelper
.
ifGuest
=
true
binding
.
rv
.
isNestedScrollingEnabled
=
false
binding
.
rv
.
isNestedScrollingEnabled
=
false
binding
.
ivItem
.
setImageResource
(
R
.
mipmap
.
d_shebei
)
binding
.
ivItem
.
setImageResource
(
R
.
mipmap
.
d_shebei
)
binding
.
view
.
setOnTouchListener
{
v
,
event
->
true
}
adapter
=
DeviceScanAdapter
(
adapter
=
DeviceScanAdapter
(
itemFinish
=
{
title
,
position
->
itemFinish
=
{
title
,
position
->
binding
.
rv
.
smoothScrollEquallyTo
(
position
)
},
finish
=
{
binding
.
rv
.
isNestedScrollingEnabled
=
true
binding
.
tvStart
.
isEnabled
=
true
binding
.
circularProgress
.
setProgressWithAnimation
(
100f
,
1500
)
},
itemStart
=
{
title
,
position
->
when
(
title
)
{
when
(
title
)
{
"Device Manufacturer"
->
{
"Device Manufacturer"
->
{
binding
.
ivItem
.
setImageResource
(
R
.
mipmap
.
d_changs
)
binding
.
ivItem
.
setImageResource
(
R
.
mipmap
.
d_changs
)
...
@@ -47,18 +56,10 @@ class DeviceScanActivity : BaseActivity<ActivityDeviceScanBinding>() {
...
@@ -47,18 +56,10 @@ class DeviceScanActivity : BaseActivity<ActivityDeviceScanBinding>() {
}
}
}
}
val
progress
=
binding
.
circularProgress
.
progress
+
25f
val
progress
=
binding
.
circularProgress
.
progress
+
25f
binding
.
circularProgress
.
setProgressWithAnimation
(
progress
,
2500
)
binding
.
circularProgress
.
setProgressWithAnimation
(
progress
,
2000
)
binding
.
rv
.
smoothScrollEquallyTo
(
position
)
}
},
)
finish
=
{
binding
.
rv
.
isNestedScrollingEnabled
=
true
binding
.
tvStart
.
isEnabled
=
true
binding
.
circularProgress
.
setProgressWithAnimation
(
100f
,
1500
)
})
binding
.
rv
.
adapter
=
adapter
binding
.
rv
.
adapter
=
adapter
binding
.
circularProgress
.
setProgressWithAnimation
(
25f
,
2500
)
}
}
...
...
app/src/main/java/com/test/easy/easycleanerjunk/activity/splash/NewSplashActivity.kt
View file @
2b50c48c
...
@@ -6,13 +6,12 @@ import android.content.Intent
...
@@ -6,13 +6,12 @@ import android.content.Intent
import
android.graphics.Color
import
android.graphics.Color
import
android.os.Build
import
android.os.Build
import
android.os.Handler
import
android.os.Handler
import
android.util.Log
import
androidx.activity.result.contract.ActivityResultContracts
import
androidx.activity.result.contract.ActivityResultContracts
import
androidx.core.view.isVisible
import
androidx.core.view.isVisible
import
com.test.easy.easycleanerjunk.databinding.ActivityLayoutSplashBinding
import
com.test.easy.easycleanerjunk.databinding.ActivityLayoutSplashBinding
import
com.test.easy.easycleanerjunk.fcm.CloseNotificationReceiver
import
com.test.easy.easycleanerjunk.helps.BaseActivity
import
com.test.easy.easycleanerjunk.helps.BaseActivity
import
com.test.easy.easycleanerjunk.helps.ConfigHelper
import
com.test.easy.easycleanerjunk.helps.ConfigHelper
import
com.test.easy.easycleanerjunk.helps.LogEx
import
com.test.easy.easycleanerjunk.helps.ads.AdmobUtils
import
com.test.easy.easycleanerjunk.helps.ads.AdmobUtils
import
com.test.easy.easycleanerjunk.utils.BarUtils
import
com.test.easy.easycleanerjunk.utils.BarUtils
...
@@ -35,12 +34,20 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
...
@@ -35,12 +34,20 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
}
}
private
var
mProgressManager
:
ProgressManager
?
=
null
private
var
mProgressManager
:
ProgressManager
?
=
null
var
jumpType
=
0
override
fun
initView
()
{
override
fun
initView
()
{
initStatusBar
()
initStatusBar
()
if
(
isDestroyed
)
{
if
(
isDestroyed
)
{
return
return
}
}
jumpType
=
intent
.
getIntExtra
(
"actionId"
,
0
)
if
(
jumpType
!=
0
)
{
val
cancelIntent
=
Intent
(
this
,
CloseNotificationReceiver
::
class
.
java
)
cancelIntent
.
action
=
CloseNotificationReceiver
.
action
cancelIntent
.
putExtra
(
CloseNotificationReceiver
.
id
,
jumpType
)
sendBroadcast
(
cancelIntent
)
}
mProgressManager
=
ProgressManager
(
binding
,
this
)
mProgressManager
=
ProgressManager
(
binding
,
this
)
if
(
ConfigHelper
.
ifAgreePrivacy
)
{
if
(
ConfigHelper
.
ifAgreePrivacy
)
{
...
@@ -55,7 +62,6 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
...
@@ -55,7 +62,6 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
}
}
override
fun
onAgreePrivacy
()
{
override
fun
onAgreePrivacy
()
{
var
jumpType
=
intent
.
getIntExtra
(
"type"
,
0
)
if
(
jumpType
==
0
)
{
if
(
jumpType
==
0
)
{
startNotification
()
startNotification
()
}
}
...
@@ -64,7 +70,7 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
...
@@ -64,7 +70,7 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
mProgressManager
?.
pauseProgress
()
mProgressManager
?.
pauseProgress
()
onProgressMax
()
onProgressMax
()
return
return
}
else
{
}
else
{
loadAd
()
loadAd
()
}
}
}
}
...
...
app/src/main/java/com/test/easy/easycleanerjunk/activity/splash/SplashJumpUtils.kt
View file @
2b50c48c
...
@@ -2,6 +2,7 @@ package com.test.easy.easycleanerjunk.activity.splash
...
@@ -2,6 +2,7 @@ package com.test.easy.easycleanerjunk.activity.splash
import
android.app.Activity
import
android.app.Activity
import
android.content.Intent
import
android.content.Intent
import
android.util.Log
import
com.test.easy.easycleanerjunk.activity.CleanGuestActivity
import
com.test.easy.easycleanerjunk.activity.CleanGuestActivity
import
com.test.easy.easycleanerjunk.activity.DeviceScanActivity
import
com.test.easy.easycleanerjunk.activity.DeviceScanActivity
import
com.test.easy.easycleanerjunk.activity.LargeFileCleanActivity
import
com.test.easy.easycleanerjunk.activity.LargeFileCleanActivity
...
@@ -21,7 +22,9 @@ object SplashJumpUtils {
...
@@ -21,7 +22,9 @@ object SplashJumpUtils {
fun
jumpNextPage
(
context
:
Activity
)
{
fun
jumpNextPage
(
context
:
Activity
)
{
var
jumpType
=
context
.
intent
.
getIntExtra
(
"type"
,
0
)
var
jumpType
=
context
.
intent
.
getIntExtra
(
"actionId"
,
0
)
Log
.
d
(
"glc"
,
"actionId: "
+
jumpType
)
if
(
jumpType
==
0
)
{
if
(
jumpType
==
0
)
{
val
uri
=
context
.
intent
.
data
val
uri
=
context
.
intent
.
data
...
...
app/src/main/java/com/test/easy/easycleanerjunk/adapter/DeviceScanAdapter.kt
View file @
2b50c48c
...
@@ -27,7 +27,8 @@ import kotlinx.coroutines.launch
...
@@ -27,7 +27,8 @@ import kotlinx.coroutines.launch
class
DeviceScanAdapter
(
class
DeviceScanAdapter
(
val
itemFinish
:
(
tittle
:
String
,
position
:
Int
)
->
Unit
,
val
itemFinish
:
(
tittle
:
String
,
position
:
Int
)
->
Unit
,
val
finish
:
()
->
Unit
val
finish
:
()
->
Unit
,
val
itemStart
:
(
tittle
:
String
,
position
:
Int
)
->
Unit
)
:
RecyclerView
.
Adapter
<
DeviceScanAdapter
.
SSS
>()
{
)
:
RecyclerView
.
Adapter
<
DeviceScanAdapter
.
SSS
>()
{
private
val
dataList
=
listOf
(
private
val
dataList
=
listOf
(
...
@@ -83,6 +84,7 @@ class DeviceScanAdapter(
...
@@ -83,6 +84,7 @@ class DeviceScanAdapter(
}
}
}
}
addListener
(
onStart
=
{
addListener
(
onStart
=
{
itemStart
.
invoke
(
data
.
tittle
,
position
)
if
(
TextUtils
.
equals
(
data
.
tittle
,
"Google Advertiser Id"
))
{
if
(
TextUtils
.
equals
(
data
.
tittle
,
"Google Advertiser Id"
))
{
var
gid
=
"unknown"
var
gid
=
"unknown"
MainScope
().
launch
(
Dispatchers
.
Main
)
{
MainScope
().
launch
(
Dispatchers
.
Main
)
{
...
...
app/src/main/java/com/test/easy/easycleanerjunk/fcm/ActionBroadcast.java
0 → 100644
View file @
2b50c48c
package
com
.
test
.
easy
.
easycleanerjunk
.
fcm
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.os.Build
;
import
android.util.Log
;
public
class
ActionBroadcast
extends
BroadcastReceiver
{
private
boolean
mIsScreenOn
=
false
;
private
boolean
isLock
=
false
;
public
static
void
initBroadcast
(
Context
context
)
{
IntentFilter
filter
=
new
IntentFilter
();
filter
.
addAction
(
Intent
.
ACTION_SCREEN_OFF
);
filter
.
addAction
(
Intent
.
ACTION_SCREEN_ON
);
filter
.
addAction
(
Intent
.
ACTION_USER_PRESENT
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
context
.
registerReceiver
(
new
ActionBroadcast
(),
filter
,
Context
.
RECEIVER_EXPORTED
);
}
else
{
context
.
registerReceiver
(
new
ActionBroadcast
(),
filter
);
}
}
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
switch
(
action
)
{
case
Intent
.
ACTION_SCREEN_ON
:
mIsScreenOn
=
true
;
break
;
case
Intent
.
ACTION_SCREEN_OFF
:
mIsScreenOn
=
false
;
isLock
=
true
;
break
;
case
Intent
.
ACTION_USER_PRESENT
:
isLock
=
false
;
if
(
mIsScreenOn
&&
!
isLock
)
{
// int locks = SPUtils.getInstance().getInt("notification_lockS", 0);
// if (locks == 1) {
// NotificationUtils.sendTimerPush();
// }
Log
.
d
(
"glc"
,
"解锁"
);
}
break
;
}
}
}
app/src/main/java/com/test/easy/easycleanerjunk/fcm/CloseNotificationReceiver.java
0 → 100644
View file @
2b50c48c
package
com
.
test
.
easy
.
easycleanerjunk
.
fcm
;
import
android.app.NotificationManager
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
com.test.easy.easycleanerjunk.utils.SPUtils
;
public
class
CloseNotificationReceiver
extends
BroadcastReceiver
{
public
static
String
action
=
"CANCEL_NOTIFICATION"
;
public
static
String
id
=
"NOTIFICATION_ID"
;
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
if
(
action
!=
null
&&
action
.
equals
(
"CANCEL_NOTIFICATION"
))
{
int
notificationId
=
intent
.
getIntExtra
(
"NOTIFICATION_ID"
,
0
);
NotificationManager
notificationManager
=
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
int
actionS
=
SPUtils
.
getInstance
().
getInt
(
"actionS"
,
0
);
if
(
actionS
==
0
)
{
notificationId
=
0
;
}
notificationManager
.
cancel
(
notificationId
);
}
}
}
app/src/main/java/com/test/easy/easycleanerjunk/fcm/FCMUtil.java
0 → 100644
View file @
2b50c48c
package
com
.
test
.
easy
.
easycleanerjunk
.
fcm
;
import
android.content.Context
;
import
android.util.Log
;
import
androidx.annotation.NonNull
;
import
com.google.android.gms.tasks.OnCompleteListener
;
import
com.google.android.gms.tasks.Task
;
import
com.google.firebase.FirebaseApp
;
import
com.google.firebase.messaging.FirebaseMessaging
;
public
class
FCMUtil
{
public
static
void
initFirebase
(
Context
context
)
{
FirebaseApp
.
initializeApp
(
context
);
}
public
static
void
subscribeToTopic
(
String
topic
)
{
FirebaseMessaging
.
getInstance
().
subscribeToTopic
(
topic
)
.
addOnCompleteListener
(
new
OnCompleteListener
<
Void
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
Void
>
task
)
{
if
(
task
.
isSuccessful
())
{
Log
.
d
(
"FCMUtil"
,
"suc"
);
}
else
{
Log
.
d
(
"FCMUtil"
,
"fail"
);
}
}
});
}
public
static
void
unsubscribeFromTopic
(
String
topic
)
{
FirebaseMessaging
.
getInstance
().
unsubscribeFromTopic
(
topic
)
.
addOnCompleteListener
(
new
OnCompleteListener
<
Void
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
Void
>
task
)
{
if
(
task
.
isSuccessful
())
{
}
else
{
}
}
});
}
}
app/src/main/java/com/test/easy/easycleanerjunk/fcm/FcmReceiver.java
0 → 100644
View file @
2b50c48c
package
com
.
test
.
easy
.
easycleanerjunk
.
fcm
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
public
class
FcmReceiver
extends
BroadcastReceiver
{
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
}
}
app/src/main/java/com/test/easy/easycleanerjunk/fcm/FcmService.java
0 → 100644
View file @
2b50c48c
package
com
.
test
.
easy
.
easycleanerjunk
.
fcm
;
import
android.util.Log
;
import
androidx.annotation.NonNull
;
import
com.google.firebase.messaging.FirebaseMessagingService
;
import
com.google.firebase.messaging.RemoteMessage
;
import
com.test.easy.easycleanerjunk.MyApplication
;
import
com.test.easy.easycleanerjunk.utils.SPUtils
;
public
class
FcmService
extends
FirebaseMessagingService
{
@Override
public
void
onMessageReceived
(
@NonNull
RemoteMessage
remoteMessage
)
{
super
.
onMessageReceived
(
remoteMessage
);
long
pushStayTime
=
remoteMessage
.
getData
().
get
(
"push_stay_time"
)
!=
null
?
Long
.
parseLong
(
remoteMessage
.
getData
().
get
(
"push_stay_time"
))
:
0
;
int
open
=
remoteMessage
.
getData
().
get
(
"open"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"open"
))
:
0
;
int
num
=
remoteMessage
.
getData
().
get
(
"num"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"num"
))
:
0
;
long
delay
=
remoteMessage
.
getData
().
get
(
"delay"
)
!=
null
?
Long
.
parseLong
(
remoteMessage
.
getData
().
get
(
"delay"
))
:
0
;
int
actionS
=
remoteMessage
.
getData
().
get
(
"actionS"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"actionS"
))
:
0
;
int
lockS
=
remoteMessage
.
getData
().
get
(
"lockS"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"lockS"
))
:
0
;
SPUtils
.
getInstance
().
put
(
"actionS"
,
actionS
);
NotificationUtil
.
sendNotification
(
MyApplication
.
context
);
Log
.
d
(
"FcmService"
,
remoteMessage
.
getData
().
toString
());
}
}
app/src/main/java/com/test/easy/easycleanerjunk/fcm/NotificationUtil.java
0 → 100644
View file @
2b50c48c
package
com
.
test
.
easy
.
easycleanerjunk
.
fcm
;
import
android.app.NotificationChannel
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.Build
;
import
android.widget.RemoteViews
;
import
androidx.core.app.NotificationCompat
;
import
com.test.easy.easycleanerjunk.R
;
import
com.test.easy.easycleanerjunk.activity.splash.NewSplashActivity
;
import
com.test.easy.easycleanerjunk.bean.ConfigBean
;
import
com.test.easy.easycleanerjunk.utils.SPUtils
;
import
java.util.Random
;
public
class
NotificationUtil
{
private
static
final
String
CHANNEL_ID
=
"notification_id"
;
// 通知渠道ID
private
static
final
String
CHANNEL_NAME
=
"fcm"
;
// 通知渠道名称
private
static
final
int
NOTIFICATION_ID
=
0
;
// 通知ID
/**
* 发送自定义布局的通知
*
* @param context 上下文对象
*/
public
static
void
sendCustomNotification
(
Context
context
,
Intent
intent
,
RemoteViews
remoteViews
)
{
NotificationManager
notificationManager
=
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
NotificationChannel
channel
=
new
NotificationChannel
(
CHANNEL_ID
,
CHANNEL_NAME
,
NotificationManager
.
IMPORTANCE_HIGH
);
channel
.
setLockscreenVisibility
(
NotificationCompat
.
VISIBILITY_PUBLIC
);
notificationManager
.
createNotificationChannel
(
channel
);
}
// 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
);
// Create the notification
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
context
,
"channel_id"
)
.
setSmallIcon
(
R
.
drawable
.
easycleanjunk_noticeicon
)
.
setContentTitle
(
"title"
)
.
setContentText
(
"message"
)
.
setContentIntent
(
pendingIntent
)
.
setPriority
(
NotificationCompat
.
PRIORITY_MAX
)
.
setContent
(
remoteViews
)
.
setCustomHeadsUpContentView
(
remoteViews
)
.
setCustomBigContentView
(
remoteViews
)
.
setCustomContentView
(
remoteViews
)
.
setAutoCancel
(
true
);
// Show the notification
if
(
SPUtils
.
getInstance
().
getInt
(
"actionS"
,
0
)
==
1
)
{
notificationManager
.
notify
(
intent
.
getIntExtra
(
"actionId"
,
0
),
builder
.
build
());
}
else
{
notificationManager
.
notify
(
0
,
builder
.
build
());
}
}
public
static
void
sendNotification
(
Context
context
)
{
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"
;
btn
=
"Clean up"
;
}
else
if
(
actionId
==
ConfigBean
.
ID_LARGE_FILE_PUSH
)
{
icon
=
R
.
drawable
.
large
;
desc
=
"Clean big files to free up storage space"
;
btn
=
"Clean up"
;
}
else
if
(
actionId
==
ConfigBean
.
ID_PHOTO_COMPRESS
)
{
icon
=
R
.
drawable
.
photo
;
desc
=
"Compress images to release more space"
;
btn
=
"Compress"
;
}
else
if
(
actionId
==
ConfigBean
.
ID_SIMILAR_IMAGE
)
{
icon
=
R
.
drawable
.
similar
;
desc
=
"Check similar photos to release more space"
;
btn
=
"Clean up"
;
}
else
{
return
;
}
remoteViews
.
setImageViewResource
(
R
.
id
.
iv_icon
,
icon
);
remoteViews
.
setTextViewText
(
R
.
id
.
tv_desc
,
desc
);
remoteViews
.
setTextViewText
(
R
.
id
.
tv_btn
,
btn
);
Intent
cancelIntent
=
new
Intent
(
context
,
CloseNotificationReceiver
.
class
);
cancelIntent
.
setAction
(
"CANCEL_NOTIFICATION"
);
cancelIntent
.
putExtra
(
CloseNotificationReceiver
.
id
,
actionId
);
int
flag
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
flag
=
PendingIntent
.
FLAG_MUTABLE
;
}
else
{
flag
=
PendingIntent
.
FLAG_UPDATE_CURRENT
;
}
Intent
intent
=
new
Intent
(
context
,
NewSplashActivity
.
class
);
intent
.
putExtra
(
"actionId"
,
actionId
);
int
btnRequestCode
=
new
Random
().
nextInt
(
1000
);
PendingIntent
btnPendingIntent
=
PendingIntent
.
getActivity
(
context
,
btnRequestCode
,
intent
,
flag
);
remoteViews
.
setOnClickPendingIntent
(
R
.
id
.
fl_btn
,
btnPendingIntent
);
PendingIntent
cancelPendingIntent
=
PendingIntent
.
getBroadcast
(
context
,
NOTIFICATION_ID
,
cancelIntent
,
flag
);
remoteViews
.
setOnClickPendingIntent
(
R
.
id
.
fl_cancel
,
cancelPendingIntent
);
sendCustomNotification
(
context
,
intent
,
remoteViews
);
}
private
static
int
currentNotificationIdIndex
=
-
1
;
public
static
int
getNextNotificationId
()
{
// 将当前通知 ID 索引加 1
currentNotificationIdIndex
++;
// 如果当前通知 ID 索引超出列表范围,则将其重置为 0
if
(
currentNotificationIdIndex
>=
NOTIFICATION_IDS
.
length
)
{
currentNotificationIdIndex
=
0
;
}
// 返回下一个通知 ID
return
NOTIFICATION_IDS
[
currentNotificationIdIndex
];
}
private
static
final
int
[]
NOTIFICATION_IDS
=
new
int
[]{
ConfigBean
.
ID_JUNK_CLEAN_PUSH
,
ConfigBean
.
ID_LARGE_FILE_PUSH
,
ConfigBean
.
ID_PHOTO_COMPRESS
,
ConfigBean
.
ID_APP_MANAGER
,
ConfigBean
.
ID_SIMILAR_IMAGE
,
ConfigBean
.
ID_SCREENSHOT_CLEAN
};
}
app/src/main/res/drawable-xxhdpi/easycleanjunk_noticeicon.png
0 → 100644
View file @
2b50c48c
1.39 KB
app/src/main/res/layout/activity_device_scan.xml
View file @
2b50c48c
...
@@ -76,6 +76,10 @@
...
@@ -76,6 +76,10 @@
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
app:layoutManager=
"androidx.recyclerview.widget.LinearLayoutManager"
app:layoutManager=
"androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem=
"@layout/item_device_info_item"
/>
tools:listitem=
"@layout/item_device_info_item"
/>
<View
android:id=
"@+id/view"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
</FrameLayout>
</FrameLayout>
...
...
app/src/main/res/layout/notification_common_notify.xml
View file @
2b50c48c
...
@@ -82,8 +82,6 @@
...
@@ -82,8 +82,6 @@
android:clickable=
"true"
android:clickable=
"true"
android:focusable=
"true"
>
android:focusable=
"true"
>
<!-- https://blog.csdn.net/zssrxt/article/details/131340741 -->
<ViewFlipper
<ViewFlipper
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
...
...
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