Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
L
location share 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
location share white
Commits
501101fb
Commit
501101fb
authored
Nov 26, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...修改常驻通知栏类型
parent
74cb6b65
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
99 deletions
+74
-99
StayJobService.kt
...ava/com/base/locationsharewhite/service/StayJobService.kt
+64
-12
LocationMapActivity.kt
.../locationsharewhite/ui/locationmap/LocationMapActivity.kt
+2
-2
LocationPresenter.kt
...se/locationsharewhite/ui/locationmap/LocationPresenter.kt
+2
-41
MainActivity.kt
.../java/com/base/locationsharewhite/ui/main/MainActivity.kt
+6
-3
MainPresenter.kt
...java/com/base/locationsharewhite/ui/main/MainPresenter.kt
+0
-41
No files found.
app/src/main/java/com/base/locationsharewhite/service/StayJobService.kt
View file @
501101fb
package
com.base.locationsharewhite.service
import
android.app.Notification
import
android.app.NotificationChannel
import
android.annotation.SuppressLint
import
android.app.NotificationManager
import
android.app.PendingIntent
import
android.app.job.JobInfo
import
android.app.job.JobParameters
import
android.app.job.JobScheduler
...
...
@@ -12,18 +10,18 @@ import android.content.ComponentName
import
android.content.Context
import
android.content.Intent
import
android.content.pm.ServiceInfo
import
android.graphics.BitmapFactory
import
android.graphics.drawable.Icon
import
android.os.Build
import
android.os.CountDownTimer
import
android.provider.MediaStore
import
android.widget.RemoteViews
import
androidx.core.app.NotificationCompat
import
androidx.core.graphics.drawable.IconCompat
import
android.os.Looper
import
androidx.work.Configuration
import
com.base.locationsharewhite.
R
import
com.base.locationsharewhite.
helper.MyApplication
import
com.base.locationsharewhite.service.StayNotification.createPermanentNotification
import
com.base.locationsharewhite.utils.LogEx
import
com.google.android.gms.location.FusedLocationProviderClient
import
com.google.android.gms.location.LocationCallback
import
com.google.android.gms.location.LocationRequest
import
com.google.android.gms.location.LocationResult
import
com.google.android.gms.location.LocationServices
import
kotlin.random.Random
...
...
@@ -40,8 +38,13 @@ class StayJobService : JobService() {
private
val
TAG
=
"StayJobService"
companion
object
{
val
ACTION_LOCATION_UPDATES
=
"ACTION_REQUEST_LOCATION_UPDATES"
private
val
NOTIFICATION_PERMANENT_ID
=
186
private
var
locationCallback
:
LocationCallback
?
=
null
fun
Context
.
requestServiceLocationUpdates
()
{
startService
(
Intent
(
this
,
StayJobService
::
class
.
java
).
apply
{
action
=
ACTION_LOCATION_UPDATES
})
}
var
isRunning
=
false
...
...
@@ -60,7 +63,11 @@ class StayJobService : JobService() {
}
override
fun
onStartCommand
(
intent
:
Intent
?,
flags
:
Int
,
startId
:
Int
):
Int
{
LogEx
.
logDebug
(
TAG
,
"onStartCommand"
)
if
(
intent
?.
action
==
ACTION_LOCATION_UPDATES
)
{
LogEx
.
logDebug
(
TAG
,
"onStartCommand ACTION_LOCATION_UPDATES"
)
requestLocationUpdates
()
}
return
super
.
onStartCommand
(
intent
,
flags
,
startId
)
}
...
...
@@ -91,6 +98,7 @@ class StayJobService : JobService() {
override
fun
onDestroy
()
{
isRunning
=
false
cancelLocationUpdates
()
super
.
onDestroy
()
}
...
...
@@ -123,5 +131,49 @@ class StayJobService : JobService() {
}
}
private
var
fusedLocationClient
:
FusedLocationProviderClient
=
LocationServices
.
getFusedLocationProviderClient
(
MyApplication
.
appContext
)
/**
* 请求google service地理位置跟新
*/
@SuppressLint
(
"MissingPermission"
)
fun
requestLocationUpdates
()
{
// 创建LocationRequest对象,并设置参数
val
locationRequest
:
LocationRequest
=
LocationRequest
.
create
()
locationRequest
.
setInterval
(
10000
)
// 设置更新间隔为10秒
locationRequest
.
setFastestInterval
(
5000
)
// 设置最快更新间隔为5秒
locationRequest
.
setPriority
(
LocationRequest
.
PRIORITY_HIGH_ACCURACY
)
// 设置位置请求的优先级
locationCallback
=
object
:
LocationCallback
()
{
override
fun
onLocationResult
(
locationResult
:
LocationResult
)
{
for
(
location
in
locationResult
.
locations
)
{
// 在这里获取最新的经纬度
val
latitude
=
location
.
latitude
val
longitude
=
location
.
longitude
}
}
}
locationCallback
?.
let
{
// 请求位置更新
fusedLocationClient
.
requestLocationUpdates
(
locationRequest
,
it
,
Looper
.
getMainLooper
())
}
}
/**
* 取消google service地理位置更新
*/
private
fun
cancelLocationUpdates
()
{
locationCallback
?.
let
{
fusedLocationClient
.
removeLocationUpdates
(
it
)
}
}
}
app/src/main/java/com/base/locationsharewhite/ui/locationmap/LocationMapActivity.kt
View file @
501101fb
...
...
@@ -20,6 +20,7 @@ import com.base.locationsharewhite.location.LocationPositionUtils
import
com.base.locationsharewhite.location.LocationShareListUtils
import
com.base.locationsharewhite.map.MapUtils.addLocationMarker
import
com.base.locationsharewhite.map.MapUtils.getLatLngByLocationManager
import
com.base.locationsharewhite.service.StayJobService.Companion.requestServiceLocationUpdates
import
com.base.locationsharewhite.ui.set.RenameActivity
import
com.base.locationsharewhite.ui.set.RenameActivity.Companion.RENAME_VIEWING_NICK_NAME
import
com.base.locationsharewhite.ui.views.DialogView.showMapTypeDialog
...
...
@@ -402,7 +403,6 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
override
fun
onPause
()
{
super
.
onPause
()
locationPresenter
.
cancelLocationUpdates
()
locationPresenter
.
cancelUploadJob
()
}
...
...
@@ -420,8 +420,8 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
binding
.
ivPermission
.
visibility
=
View
.
VISIBLE
}
else
{
binding
.
ivPermission
.
visibility
=
View
.
GONE
locationPresenter
.
requestLocationUpdates
()
locationPresenter
.
startUploadMyLocation
()
requestServiceLocationUpdates
()
}
refreshNickName
()
}
...
...
app/src/main/java/com/base/locationsharewhite/ui/locationmap/LocationPresenter.kt
View file @
501101fb
...
...
@@ -7,6 +7,7 @@ import android.os.Looper
import
androidx.lifecycle.LifecycleCoroutineScope
import
com.base.locationsharewhite.location.LocationPositionUtils.uploadMyLocation
import
com.base.locationsharewhite.map.MapUtils.getLatLngByLocationManager
import
com.base.locationsharewhite.service.StayJobService.Companion.requestServiceLocationUpdates
import
com.base.locationsharewhite.utils.BatteryUtils.getBatteryLevel
import
com.base.locationsharewhite.utils.LogEx
import
com.google.android.gms.location.FusedLocationProviderClient
...
...
@@ -29,7 +30,6 @@ class LocationPresenter(
private
var
TAG
=
"LocationPresenter"
private
var
uploadJob
:
Job
?
=
null
//google的地理位置服务
private
var
fusedLocationClient
:
FusedLocationProviderClient
=
LocationServices
.
getFusedLocationProviderClient
(
activity
)
var
googleLocation
:
LatLng
?
=
null
...
...
@@ -69,7 +69,6 @@ class LocationPresenter(
}
}
@SuppressLint
(
"MissingPermission"
)
fun
getGoogleServiceLocation
()
{
fusedLocationClient
.
lastLocation
...
...
@@ -92,46 +91,8 @@ class LocationPresenter(
uploadJob
=
null
}
private
var
locationCallback
:
LocationCallback
?
=
null
/**
* 请求google service地理位置跟新
*/
@SuppressLint
(
"MissingPermission"
)
fun
requestLocationUpdates
()
{
// 创建LocationRequest对象,并设置参数
val
locationRequest
:
LocationRequest
=
LocationRequest
.
create
()
locationRequest
.
setInterval
(
10000
)
// 设置更新间隔为10秒
locationRequest
.
setFastestInterval
(
5000
)
// 设置最快更新间隔为5秒
locationRequest
.
setPriority
(
LocationRequest
.
PRIORITY_HIGH_ACCURACY
)
// 设置位置请求的优先级
locationCallback
=
object
:
LocationCallback
()
{
override
fun
onLocationResult
(
locationResult
:
LocationResult
)
{
for
(
location
in
locationResult
.
locations
)
{
// 在这里获取最新的经纬度
val
latitude
=
location
.
latitude
val
longitude
=
location
.
longitude
}
}
}
locationCallback
?.
let
{
// 请求位置更新
fusedLocationClient
.
requestLocationUpdates
(
locationRequest
,
it
,
Looper
.
getMainLooper
())
}
companion
object
{
}
/**
* 取消google service地理位置更新
*/
fun
cancelLocationUpdates
()
{
locationCallback
?.
let
{
fusedLocationClient
.
removeLocationUpdates
(
it
)
}
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/ui/main/MainActivity.kt
View file @
501101fb
...
...
@@ -2,6 +2,7 @@ package com.base.locationsharewhite.ui.main
import
android.Manifest
import
android.app.Dialog
import
android.app.job.JobService
import
android.content.Intent
import
android.graphics.Color
import
android.os.Build
...
...
@@ -17,6 +18,9 @@ import com.base.locationsharewhite.helper.BaseActivity
import
com.base.locationsharewhite.helper.MyApplication
import
com.base.locationsharewhite.location.LocationLoginUtils
import
com.base.locationsharewhite.map.MapUtils.addLocationMarker
import
com.base.locationsharewhite.service.StayJobService
import
com.base.locationsharewhite.service.StayJobService.Companion.ACTION_LOCATION_UPDATES
import
com.base.locationsharewhite.service.StayJobService.Companion.requestServiceLocationUpdates
import
com.base.locationsharewhite.ui.howuse.HowUseActivity
import
com.base.locationsharewhite.ui.locationmap.LocationMapActivity
import
com.base.locationsharewhite.ui.set.SettingActivity
...
...
@@ -103,12 +107,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnMapReadyCallback {
if
(
isRecreate
)
{
return
}
mainPresenter
.
requestLocationUpdates
()
mainPresenter
.
startLocationJob
(
lifecycleScope
)
showAllowAllTimeDialog
()
isRunning
=
true
}
...
...
@@ -133,6 +135,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnMapReadyCallback {
// toast("不显示权限始终允许弹窗")
allowAllTimeDialog
?.
dismiss
()
allowAllTimeDialog
=
null
requestServiceLocationUpdates
()
}
}
...
...
@@ -178,7 +182,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnMapReadyCallback {
override
fun
onPause
()
{
super
.
onPause
()
if
(
isRunning
)
{
mainPresenter
.
cancelLocationUpdates
()
mainPresenter
.
cancelLocationJob
()
}
}
...
...
app/src/main/java/com/base/locationsharewhite/ui/main/MainPresenter.kt
View file @
501101fb
...
...
@@ -55,47 +55,6 @@ class MainPresenter(
return
latLng
}
private
var
locationCallback
:
LocationCallback
?
=
null
/**
* 请求google service地理位置跟新
*/
@SuppressLint
(
"MissingPermission"
)
fun
requestLocationUpdates
()
{
// 创建LocationRequest对象,并设置参数
val
locationRequest
:
LocationRequest
=
LocationRequest
.
create
()
locationRequest
.
setInterval
(
10000
)
// 设置更新间隔为10秒
locationRequest
.
setFastestInterval
(
5000
)
// 设置最快更新间隔为5秒
locationRequest
.
setPriority
(
LocationRequest
.
PRIORITY_HIGH_ACCURACY
)
// 设置位置请求的优先级
locationCallback
=
object
:
LocationCallback
()
{
override
fun
onLocationResult
(
locationResult
:
LocationResult
)
{
for
(
location
in
locationResult
.
locations
)
{
// 在这里获取最新的经纬度
val
latitude
=
location
.
latitude
val
longitude
=
location
.
longitude
}
}
}
locationCallback
?.
let
{
// 请求位置更新
fusedLocationClient
.
requestLocationUpdates
(
locationRequest
,
it
,
Looper
.
getMainLooper
())
}
}
/**
* 取消google service地理位置更新
*/
fun
cancelLocationUpdates
()
{
locationCallback
?.
let
{
fusedLocationClient
.
removeLocationUpdates
(
it
)
}
}
var
uiLocationCallback
:
((
latLng
:
LatLng
)
->
Unit
)?
=
null
private
var
locationJob
:
Job
?
=
null
...
...
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