Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
swiftcleanerphonehelper
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
swiftcleanerphonehelper
Commits
528765db
Commit
528765db
authored
Dec 20, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
ab3f6ff0
Pipeline
#1384
canceled with stages
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
24 deletions
+10
-24
Global.java
.../main/java/com/swiftcleaner/chovey/model/bean/Global.java
+1
-0
BatteryStatusReceiver.kt
...rc/main/java/com/zxdemo/receiver/BatteryStatusReceiver.kt
+9
-24
No files found.
app/src/main/java/com/swiftcleaner/chovey/model/bean/Global.java
View file @
528765db
...
@@ -19,5 +19,6 @@ public class Global {
...
@@ -19,5 +19,6 @@ public class Global {
public
static
String
lockNotificationStatus
=
"lockNotificationStatus"
;
public
static
String
lockNotificationStatus
=
"lockNotificationStatus"
;
public
static
String
batteryNotificationStatus
=
"batteryNotificationStatus"
;
}
}
app/src/main/java/com/zxdemo/receiver/BatteryStatusReceiver.kt
View file @
528765db
...
@@ -4,17 +4,13 @@ import android.content.BroadcastReceiver
...
@@ -4,17 +4,13 @@ import android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Context
import
android.content.Intent
import
android.content.Intent
import
android.os.BatteryManager
import
android.os.BatteryManager
import
android.os.Build
import
android.util.Log
import
android.util.Log
import
androidx.annotation.RequiresApi
import
com.swiftcleaner.chovey.model.bean.Global.batteryNotificationStatus
import
com.zxdemo.notity.NotificationUtils
import
com.zxdemo.notity.NotificationUtils
import
com.zxdemo.utils.SpUtils
import
com.zxdemo.utils.SpUtils
import
java.time.LocalDateTime
import
java.time.format.DateTimeFormatter
import
java.time.temporal.ChronoUnit
class
BatteryStatusReceiver
()
:
BroadcastReceiver
()
{
class
BatteryStatusReceiver
()
:
BroadcastReceiver
()
{
@RequiresApi
(
Build
.
VERSION_CODES
.
O
)
override
fun
onReceive
(
context
:
Context
?,
batteryIntent
:
Intent
?)
{
override
fun
onReceive
(
context
:
Context
?,
batteryIntent
:
Intent
?)
{
val
level
=
batteryIntent
?.
getIntExtra
(
BatteryManager
.
EXTRA_LEVEL
,
-
1
)
?:
-
1
val
level
=
batteryIntent
?.
getIntExtra
(
BatteryManager
.
EXTRA_LEVEL
,
-
1
)
?:
-
1
val
scale
=
batteryIntent
?.
getIntExtra
(
BatteryManager
.
EXTRA_SCALE
,
-
1
)
?:
-
1
val
scale
=
batteryIntent
?.
getIntExtra
(
BatteryManager
.
EXTRA_SCALE
,
-
1
)
?:
-
1
...
@@ -27,24 +23,17 @@ class BatteryStatusReceiver() : BroadcastReceiver() {
...
@@ -27,24 +23,17 @@ class BatteryStatusReceiver() : BroadcastReceiver() {
val
voltage
=
batteryIntent
?.
getIntExtra
(
BatteryManager
.
EXTRA_VOLTAGE
,
-
1
)
?:
-
1
val
voltage
=
batteryIntent
?.
getIntExtra
(
BatteryManager
.
EXTRA_VOLTAGE
,
-
1
)
?:
-
1
val
temperature
=
batteryIntent
?.
getIntExtra
(
BatteryManager
.
EXTRA_TEMPERATURE
,
-
1
)
?:
-
1
val
temperature
=
batteryIntent
?.
getIntExtra
(
BatteryManager
.
EXTRA_TEMPERATURE
,
-
1
)
?:
-
1
val
technology
=
batteryIntent
?.
getStringExtra
(
BatteryManager
.
EXTRA_TECHNOLOGY
)
?:
"Unknown"
val
technology
=
batteryIntent
?.
getStringExtra
(
BatteryManager
.
EXTRA_TECHNOLOGY
)
?:
"Unknown"
val
batteryPct
=
level
*
100
/
scale
.
toFloat
()
val
batteryPct
=
level
*
100
/
scale
.
toFloat
()
val
intervalTime
=
SpUtils
.
getInstance
().
getInt
(
"batteryNotificationInterval"
,
5
)
var
batteryNotificationStatus
=
SpUtils
.
getInstance
().
getInt
(
batteryNotificationStatus
,
0
)
var
current
=
LocalDateTime
.
now
()
var
lastTime
=
SpUtils
.
getInstance
().
getString
(
"NOTICE_BATTERY_TIME"
,
""
)
var
parsedDateTime
=
current
if
(
lastTime
!=
""
)
{
parsedDateTime
=
LocalDateTime
.
parse
(
lastTime
,
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm"
))
}
var
batteryNotificationStatus
=
SpUtils
.
getInstance
().
getInt
(
"batteryNotificationStatus"
,
0
)
val
minutesBetween
=
ChronoUnit
.
MINUTES
.
between
(
parsedDateTime
,
current
)
// Log.d("TAG", "onReceive:电池 $minutesBetween $intervalTime")
if
((
batteryNotificationStatus
==
1
&&
(
minutesBetween
>
intervalTime
&&
minutesBetween
.
toInt
()
==
0
))
&&
(
state
==
BatteryManager
.
BATTERY_STATUS_CHARGING
||
(
level
<
20
&&
level
>
10
)))
{
if
(
batteryNotificationStatus
==
1
&&
(
level
in
11
..
19
)
&&
state
==
BatteryManager
.
BATTERY_STATUS_CHARGING
)
{
Log
.
d
(
"TAG"
,
"onReceive: 电池推送"
)
Log
.
d
(
"TAG"
,
"onReceive: 电池推送"
)
if
(
context
!=
null
)
{
if
(
context
!=
null
)
{
NotificationUtils
.
sendNotification
(
NotificationUtils
.
sendNotification
(
...
@@ -52,10 +41,6 @@ class BatteryStatusReceiver() : BroadcastReceiver() {
...
@@ -52,10 +41,6 @@ class BatteryStatusReceiver() : BroadcastReceiver() {
"showNotification"
,
"showNotification"
,
"receive_battery"
"receive_battery"
)
)
SpUtils
.
getInstance
().
putString
(
"NOTICE_BATTERY_TIME"
,
current
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm"
))
)
}
}
}
}
}
}
...
...
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