Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
Scan QR Code Barcode Reader
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
Scan QR Code Barcode Reader
Commits
6767642c
Commit
6767642c
authored
Jan 08, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
e3fd4a4c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
9 deletions
+84
-9
FcmReceiver.kt
app/src/main/java/com/base/scanqr/fcm/FcmReceiver.kt
+31
-0
MessagingService.kt
app/src/main/java/com/base/scanqr/fcm/MessagingService.kt
+33
-0
MyNotificationManager.kt
...com/base/scanqr/fcm/notification/MyNotificationManager.kt
+7
-7
NotificationUiUtil.kt
...va/com/base/scanqr/fcm/notification/NotificationUiUtil.kt
+11
-2
stay_notification_big_scan.xml
app/src/main/res/layout/stay_notification_big_scan.xml
+1
-0
stay_notification_small_scan.xml
app/src/main/res/layout/stay_notification_small_scan.xml
+1
-0
No files found.
app/src/main/java/com/base/scanqr/fcm/FcmReceiver.kt
View file @
6767642c
...
...
@@ -4,10 +4,13 @@ import android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Intent
import
com.base.scanqr.bean.NotificationSendBean
import
com.base.scanqr.bean.NotificationSendBean.Companion.ACTION_ID_SCAN
import
com.base.scanqr.bean.NotificationSendBean.Companion.POPUP_WHERE_FCM
import
com.base.scanqr.fcm.notification.MyNotificationManager
import
com.base.scanqr.helper.EventUtils.event
import
com.base.scanqr.utils.LogEx
import
java.util.Calendar
import
java.util.TimeZone
class
FcmReceiver
:
BroadcastReceiver
()
{
...
...
@@ -17,6 +20,34 @@ class FcmReceiver : BroadcastReceiver() {
event
(
"FCM_Received"
,
"FcmReceiver"
,
null
)
LogEx
.
logDebug
(
TAG
,
"FCM FcmReceiver"
)
val
sendBean
=
NotificationSendBean
(
context
,
POPUP_WHERE_FCM
,
canSend
=
{
true
},
sendSuccess
=
{})
if
(
isWithinTimeRange
())
{
val
map
=
hashMapOf
<
String
,
Any
>()
map
[
"AM"
]
=
"Scan today's product information."
sendBean
.
valueMap
=
map
sendBean
.
actionId
=
ACTION_ID_SCAN
}
MyNotificationManager
.
submitSendBean
(
sendBean
)
}
private
fun
isWithinTimeRange
():
Boolean
{
// 获取当前时间的Calendar实例
val
now
:
Calendar
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"UTC"
))
// 设置起始时间8:30 AM
val
startTime
:
Calendar
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"UTC"
))
startTime
.
set
(
Calendar
.
HOUR_OF_DAY
,
8
)
startTime
.
set
(
Calendar
.
MINUTE
,
30
)
startTime
.
set
(
Calendar
.
SECOND
,
0
)
startTime
.
set
(
Calendar
.
MILLISECOND
,
0
)
// 设置结束时间10:30 AM
val
endTime
:
Calendar
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"UTC"
))
endTime
.
set
(
Calendar
.
HOUR_OF_DAY
,
10
)
endTime
.
set
(
Calendar
.
MINUTE
,
30
)
endTime
.
set
(
Calendar
.
SECOND
,
0
)
endTime
.
set
(
Calendar
.
MILLISECOND
,
0
)
// 判断当前时间是否在指定时间段内
return
now
.
after
(
startTime
)
&&
now
.
before
(
endTime
)
}
}
app/src/main/java/com/base/scanqr/fcm/MessagingService.kt
View file @
6767642c
...
...
@@ -2,6 +2,7 @@ package com.base.scanqr.fcm
import
android.annotation.SuppressLint
import
com.base.scanqr.bean.NotificationSendBean
import
com.base.scanqr.bean.NotificationSendBean.Companion.ACTION_ID_SCAN
import
com.base.scanqr.bean.NotificationSendBean.Companion.POPUP_WHERE_FCM
import
com.base.scanqr.fcm.notification.MyNotificationManager
import
com.base.scanqr.helper.EventUtils.event
...
...
@@ -9,6 +10,8 @@ import com.base.scanqr.utils.LogEx
import
com.google.firebase.messaging.FirebaseMessagingService
import
com.google.firebase.messaging.RemoteMessage
import
org.json.JSONObject
import
java.util.Calendar
import
java.util.TimeZone
@SuppressLint
(
"MissingFirebaseInstanceTokenRefresh"
)
class
MessagingService
:
FirebaseMessagingService
()
{
...
...
@@ -19,6 +22,36 @@ class MessagingService : FirebaseMessagingService() {
event
(
"FCM_Received"
,
"MessagingService"
,
data
)
LogEx
.
logDebug
(
TAG
,
"FCM MessagingService"
)
val
sendBean
=
NotificationSendBean
(
this
,
POPUP_WHERE_FCM
,
canSend
=
{
true
},
sendSuccess
=
{})
if
(
isWithinTimeRange
())
{
val
map
=
hashMapOf
<
String
,
Any
>()
map
[
"AM"
]
=
"Scan today's product information."
sendBean
.
valueMap
=
map
sendBean
.
actionId
=
ACTION_ID_SCAN
}
MyNotificationManager
.
submitSendBean
(
sendBean
)
}
private
fun
isWithinTimeRange
():
Boolean
{
// 获取当前时间的Calendar实例
val
now
:
Calendar
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"UTC"
))
// 设置起始时间8:30 AM
val
startTime
:
Calendar
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"UTC"
))
startTime
.
set
(
Calendar
.
HOUR_OF_DAY
,
8
)
startTime
.
set
(
Calendar
.
MINUTE
,
30
)
startTime
.
set
(
Calendar
.
SECOND
,
0
)
startTime
.
set
(
Calendar
.
MILLISECOND
,
0
)
// 设置结束时间10:30 AM
val
endTime
:
Calendar
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"UTC"
))
endTime
.
set
(
Calendar
.
HOUR_OF_DAY
,
10
)
endTime
.
set
(
Calendar
.
MINUTE
,
30
)
endTime
.
set
(
Calendar
.
SECOND
,
0
)
endTime
.
set
(
Calendar
.
MILLISECOND
,
0
)
// 判断当前时间是否在指定时间段内
return
now
.
after
(
startTime
)
&&
now
.
before
(
endTime
)
}
}
\ No newline at end of file
app/src/main/java/com/base/scanqr/fcm/notification/MyNotificationManager.kt
View file @
6767642c
...
...
@@ -207,13 +207,13 @@ object MyNotificationManager {
* 只测某些类型
*/
private
var
testWhere
=
listOf
(
POPUP_WHERE_LOCK
,
POPUP_WHERE_BATTERY
,
POPUP_WHERE_PACKAGE
,
POPUP_WHERE_WORK_MANAGER
,
POPUP_WHERE_ALARM
,
POPUP_WHERE_TIMER
,
POPUP_WHERE_FILE_JOB
,
//
POPUP_WHERE_LOCK,
//
POPUP_WHERE_BATTERY,
//
POPUP_WHERE_PACKAGE,
//
POPUP_WHERE_WORK_MANAGER,
//
POPUP_WHERE_ALARM,
//
POPUP_WHERE_TIMER,
//
POPUP_WHERE_FILE_JOB,
POPUP_WHERE_FCM
)
}
\ No newline at end of file
app/src/main/java/com/base/scanqr/fcm/notification/NotificationUiUtil.kt
View file @
6767642c
...
...
@@ -32,8 +32,17 @@ object NotificationUiUtil {
fun
setNotification
(
sendBean
:
NotificationSendBean
)
{
when
(
sendBean
.
actionId
)
{
ACTION_ID_SCAN
->
{
sendBean
.
bigRemoteViews
=
RemoteViews
(
MyApplication
.
appContext
.
packageName
,
R
.
layout
.
stay_notification_big_scan
)
sendBean
.
smallRemoteViews
=
RemoteViews
(
MyApplication
.
appContext
.
packageName
,
R
.
layout
.
stay_notification_small_scan
)
val
bigRemoteViews
=
RemoteViews
(
MyApplication
.
appContext
.
packageName
,
R
.
layout
.
stay_notification_big_scan
)
val
smallRemoteViews
=
RemoteViews
(
MyApplication
.
appContext
.
packageName
,
R
.
layout
.
stay_notification_small_scan
)
if
(
sendBean
.
valueMap
.
isNotEmpty
())
{
val
value
=
sendBean
.
valueMap
[
"AM"
]
val
string
=
(
value
as
String
?)
?:
"Scan today's product information."
bigRemoteViews
.
setTextViewText
(
R
.
id
.
tvDesc
,
string
)
smallRemoteViews
.
setTextViewText
(
R
.
id
.
tvDesc
,
string
)
}
sendBean
.
bigRemoteViews
=
bigRemoteViews
sendBean
.
smallRemoteViews
=
smallRemoteViews
}
ACTION_ID_WIFI
->
{
...
...
app/src/main/res/layout/stay_notification_big_scan.xml
View file @
6767642c
...
...
@@ -18,6 +18,7 @@
tools:ignore=
"UselessParent"
>
<TextView
android:id=
"@+id/tvDesc"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"16dp"
...
...
app/src/main/res/layout/stay_notification_small_scan.xml
View file @
6767642c
...
...
@@ -17,6 +17,7 @@
android:textStyle=
"bold"
/>
<TextView
android:id=
"@+id/tvDesc"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"2dp"
...
...
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