定位上传1

This commit is contained in:
2024-03-29 15:34:57 +08:00
parent 87eb1734fa
commit bd050080c5
13 changed files with 507 additions and 34 deletions
+3 -1
View File
@@ -92,7 +92,9 @@
android:name="com.amap.api.v2.apikey"
android:value="e0c32c80b14f78b770b3671add9c4515" />
<service android:name="com.amap.api.location.APSService" />
<service android:name="com.amap.api.location.APSService"
android:foregroundServiceType="location"/>
<service android:name=".service.UpLocationService"/>
<activity
android:name=".ui.LauncherActivity"
+43 -24
View File
@@ -1,16 +1,25 @@
package com.dahe.gldriver.base
import android.app.Application
import android.app.PendingIntent
import android.app.PendingIntent.*
import android.content.Context
import android.content.Intent
import android.util.Log
import com.dahe.gldriver.BuildConfig
import com.dahe.gldriver.R
import com.dahe.gldriver.net.Api
import com.dahe.gldriver.oss.OssServiceUtil
import com.dahe.gldriver.push.PushHelper
import com.dahe.gldriver.ui.HomeActivity
import com.dahe.gldriver.utils.OrderUtils
import com.dahe.mylibrary.CommonBaseLibrary
import com.dahe.mylibrary.utils.AppUtils
import com.esign.esignsdk.EsignSdk
import com.github.gzuliyujiang.dialog.DialogConfig
import com.github.gzuliyujiang.dialog.DialogStyle
import com.gyf.cactus.Cactus
import com.gyf.cactus.callback.CactusBackgroundCallback
import com.tencent.bugly.crashreport.CrashReport
import com.umeng.commonsdk.UMConfigure
import com.umeng.message.PushAgent
@@ -46,30 +55,40 @@ class App : Application() {
EsignSdk.getInstance().init(AppConfig.E_KEY, AppConfig.E_LICENSE)
initUmeng()
// PendingIntent pendingIntent =
// PendingIntent.getActivity(this, 0, new Intent(this, HomeActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
// Cactus.getInstance()
// .isDebug(true)
// //可选,设置通知栏点击事件
// .setPendingIntent(pendingIntent)
//// .setBackgroundMusicEnabled(true)//可选,退到后台是否可以播放音乐
//// .setMusicId(R.raw.main) //可选,设置音乐
//// .setPendingIntent(pendingIntent)//可选,设置通知栏点击事件
//// .addCallback(new CactusCallback())//可选,运行时回调
var pendingIntent: PendingIntent = getActivity(
applicationContext, 0,
Intent(applicationContext, HomeActivity::class.java),
FLAG_UPDATE_CURRENT
)
Cactus.instance
.isDebug(true)
.setChannelId(AppUtils.getAppPackageName())
.setChannelName(AppUtils.getAppPackageName())
//可选,设置通知栏点击事件
.setPendingIntent(pendingIntent)
.setBackgroundMusicEnabled(true)//可选,退到后台是否可以播放音乐
// .setMusicInterval(20000)//设置音乐间隔时间,时间间隔越长,越省电,默认间隔时间是0
.setMusicId(R.raw.main) //可选,设置音乐
// .addCallback(new CactusCallback())//可选,运行时回调
// .setCrashRestartUIEnabled(true) //可选,设置奔溃可以重启,google原生rom android 10以下可以正常重启
// .setCrashRestartUIEnabled(true)//可选,设置奔溃可以重启,google原生rom android 10以下可以正常重启
// .setTitle("大河好运")
// .hideNotificationAfterO(true)
// .setSmallIcon(R.drawable.right_icon)
// .addBackgroundCallback(new CactusBackgroundCallback() {
// @Override
// public void onBackground(boolean b) {
// if (b){
//// getBillLocation();
// }
// }
// })
// .register(this);
.setTitle("大河好运")
.setContent("大河好运司机端为您提供服务")
.hideNotificationAfterO(true)
.setSmallIcon(R.mipmap.app_icon)
.addCallback {
OrderUtils.getInstance().upLocation(applicationContext)
println("22222222222")
Log.i("lijia","11111111")
}
.addBackgroundCallback(object : CactusBackgroundCallback {
override fun onBackground(background: Boolean) {
if (background) {
// getBillLocation();
}
}
})
.register(this)
}
override fun attachBaseContext(base: Context) {
@@ -104,7 +123,7 @@ class App : Application() {
// 推送注册
val api = PushAgent.getInstance(this)
PushHelper.setting(api)
api.register(object : UPushRegisterCallback{
api.register(object : UPushRegisterCallback {
override fun onSuccess(p0: String?) {//注册厂商通道
Log.e(
"TAG",
@@ -13,6 +13,7 @@ object AppConfig {
const val DATA = "DA_HE_DATA"
const val PHONE = "DA_HE_PHONE"
const val ORDER_ID = "DA_HE_ORDER_ID"
const val NEED_UP_ORDER = "DA_HE_NEED_UP_ORDER"
const val CAR_ID = "DA_HE_CAR_ID"
const val IS_SHOW = "DA_HE_IS_SHOW"
const val IS_FIRST_OPEN = "DA_HE_IS_FIRST_OPEN"
@@ -224,6 +224,22 @@ data class Resources(
)
/**
* 司机轨迹上传
* @property latitude String
* @property longitude String
* @property orderId String
* @property waybillId String
* @constructor
*/
data class UpLocation(
val latitude: Double,
val longitude: Double,
val orderId: String,
val waybillId: String
)
+10 -2
View File
@@ -22,6 +22,7 @@ import com.dahe.gldriver.bean.UpBankInfoBean
import com.dahe.gldriver.bean.UpCaptain
import com.dahe.gldriver.bean.UpDriverInfoBean
import com.dahe.gldriver.bean.UpDrivingInfoBean
import com.dahe.gldriver.bean.UpLocation
import com.dahe.gldriver.bean.UpPart
import com.dahe.gldriver.bean.UpPersonInfoBean
import com.dahe.gldriver.bean.UpPicBean
@@ -250,6 +251,15 @@ interface Api {
fun orderDetail(@Query("orderId") orderId: String): Observable<CommonResponseBean<OrderDetailBean>>
/**
* 司机轨迹上传
* @param [Error type: Missed a type for a value parameter <no name provided>]
* @return Observable<CommonResponseBean<Any>>
*/
@POST(BASE_URL + "driver/driverWaybill/driverUploadLocus")
fun driverUploadLocus(@Body upLocation: UpLocation): Observable<CommonResponseBean<Any>>
/**
* 司机接单
* */
@@ -487,8 +497,6 @@ interface Api {
fun safeClassroomDetail(@Query("classroomId") problemId: String): Observable<CommonResponseBean<QueDetail>>
/**
* 获取APP最新版本信息
* @return Observable<CommonResponseBean<ProBean>>
@@ -0,0 +1,142 @@
package com.dahe.gldriver.service
import android.app.Service
import android.content.Intent
import android.os.Environment
import android.os.Handler
import android.os.IBinder
import android.os.Message
import android.util.Log
import com.amap.api.location.AMapLocation
import com.dahe.gldriver.bean.OrderDetailBean
import com.dahe.gldriver.bean.UpLocation
import com.dahe.gldriver.net.BaseObserver
import com.dahe.gldriver.net.DataManager
import com.dahe.gldriver.net.RxHttpCallBack
import com.dahe.gldriver.utils.GDLocationUtils
import com.dahe.mylibrary.net.CommonResponseBean
import com.dahe.mylibrary.utils.CrashHandler
import com.dahe.mylibrary.utils.CrashHandler2
import com.dahe.mylibrary.utils.FileIOUtils
import com.dahe.mylibrary.utils.ToastUtils
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers
import java.io.File
import java.io.FileOutputStream
import java.io.PrintWriter
import java.io.StringWriter
import java.io.Writer
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Timer
import java.util.TimerTask
/**
* @ClassName UpLocationService
* @Author john
* @Date 2024/3/28 09:08
* @Description TODO
*/
class UpLocationService : Service() {
private val hd = Handler { msg: Message ->
when (msg.what) {
123 -> {
//获取文件输出路径
val path = Environment.getExternalStorageDirectory()
.toString() + "/crashinfo/"
val time: String = formatter.format(Date())
val time2: String = formatter2.format(Date())
val fileName = "crash-$time.txt"
GDLocationUtils.instance.getLocation(application) {
if (it.getErrorCode() == 0 && it.latitude != 0.0) {
FileIOUtils.writeFileFromString(
path + fileName,
"""当前时间:${time2},经纬度:${it.latitude}:${it.longitude}""",
true
)
} else {
FileIOUtils.writeFileFromString(
path + fileName,
"""当前时间:${time2},经纬度:${it.latitude}${it.errorInfo}""",
true
)
}
}
// var orderString = BaseSPUtils.get(application,AppConfig.NEED_UP_ORDER,"") as String
// if (!orderString.isNullOrEmpty()){
// var order = Gson().fromJson(orderString,OrderDetailBean::class.java)
// GDLocationUtils.instance.getLocation(application){
// loadLocation(it,order)
//
// }
// }else{
//
// }
}
}
false
}
private val formatter: DateFormat = SimpleDateFormat("yyyy-MM-dd")
private val formatter2: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
override fun onBind(intent: Intent?): IBinder? {
return null
}
override fun onRebind(intent: Intent?) {
super.onRebind(intent)
}
private val timeSum = 1000 * 60 * 3
// private val timeSum = 3000
private var timer: Timer? = null
override fun onCreate() {
super.onCreate()
Log.e("开始循环上传,等待100ms", "-----")
timer = Timer()
timer?.schedule(object : TimerTask() {
override fun run() {
val msg = Message.obtain()
msg.what = 123
hd.sendMessage(msg)
}
}, 1000, timeSum.toLong())
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
return START_STICKY
}
private fun loadLocation(loc: AMapLocation, order: OrderDetailBean) {
DataManager.getInstance().driverUploadLocus(
UpLocation(
loc.latitude,
loc.longitude,
order.orderId,
order.waybillId
)
)
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(BaseObserver(application, object : RxHttpCallBack<Any>() {
override fun onSuccess(t: CommonResponseBean<Any>) {
super.onSuccess(t)
}
}))
}
override fun onDestroy() {
super.onDestroy()
if (timer != null) {
timer?.cancel()
timer = null
}
}
}
@@ -92,6 +92,7 @@ class HomeActivity : BaseActivity<ActivityHomeBinding>(), OnTabSelectListener,
Manifest.permission.CAMERA,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION,
)
@@ -1,11 +1,9 @@
package com.dahe.gldriver.ui.home
import android.Manifest
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.widget.LinearLayout
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.dahe.gldriver.R
@@ -14,6 +12,7 @@ import com.dahe.gldriver.adapter.WaybillAdapter
import com.dahe.gldriver.base.AppConfig
import com.dahe.gldriver.base.WebActivity
import com.dahe.gldriver.bean.GridBean
import com.dahe.gldriver.bean.OrderDetailBean
import com.dahe.gldriver.databinding.FragmentHomeBinding
import com.dahe.gldriver.net.BaseObserver
import com.dahe.gldriver.net.DataManager
@@ -159,6 +158,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(), RefreshCallBack {
)
}
}))
//执行中运单轨迹上传
OrderUtils.getInstance().upLocation(mContext)
}
private fun initRecy() {
@@ -1,17 +1,26 @@
package com.dahe.gldriver.utils
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.dahe.gldriver.base.App
import com.dahe.gldriver.base.AppConfig
import com.dahe.gldriver.base.AppConfig.NEED_UP_ORDER
import com.dahe.gldriver.bean.CarBean
import com.dahe.gldriver.bean.OrderDetailBean
import com.dahe.gldriver.bean.UpLocation
import com.dahe.gldriver.callback.OnResultListener
import com.dahe.gldriver.net.BaseObserver
import com.dahe.gldriver.net.DataManager
import com.dahe.gldriver.net.RxHttpCallBack
import com.dahe.gldriver.service.UpLocationService
import com.dahe.gldriver.ui.waybill.activity.WaybillLoadActivity
import com.dahe.mylibrary.base.SingletonNoPHolder
import com.dahe.mylibrary.net.CommonResponseBean
import com.dahe.mylibrary.utils.ActivityUtils
import com.dahe.mylibrary.utils.BaseSPUtils
import com.google.gson.Gson
import com.gyf.cactus.Cactus
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers
@@ -83,7 +92,7 @@ class OrderUtils private constructor() {
*
* 接单(包含选择车辆)->装货
* */
fun goReceWaybill(context: Context, orderId: String,listener:OnResultListener) {
fun goReceWaybill(context: Context, orderId: String, listener: OnResultListener) {
//选择车辆
DataManager.getInstance().carList()
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
@@ -95,7 +104,7 @@ class OrderUtils private constructor() {
CommonPopUtils.getInstance()
.showCarList(context, t.data) {
//接单接口
receivingOrders(context, orderId, it,listener)
receivingOrders(context, orderId, it, listener)
}
} else {
//单量车,直接默认当前车辆 ,接单接口
@@ -141,4 +150,37 @@ class OrderUtils private constructor() {
})
)
}
/**
* 上传运行中运单轨迹
* @param context Context
*/
fun upLocation(context: Context) {
DataManager.getInstance().orderDetail("")
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(BaseObserver(context, object : RxHttpCallBack<OrderDetailBean>() {
override fun onSuccess(t: CommonResponseBean<OrderDetailBean>) {
super.onSuccess(t)
if (t.data != null) {
BaseSPUtils.put(context, NEED_UP_ORDER, Gson().toJson(t.data))
context.startService(Intent(context, UpLocationService::class.java))
// if (!Cactus.instance.isRunning(context)) {
// Cactus.instance.addCallback {
// context.startService(Intent(context, UpLocationService::class.java))
// }.restart(context)
// }else{
// Cactus.instance.addCallback {
// context.startService(Intent(context, UpLocationService::class.java))
// }.restart(context)
// }
// OrderUtils.getInstance().upLocation("","",t.data.orderId,t.data.waybillId)
} else {
context.stopService(Intent(context, UpLocationService::class.java))
BaseSPUtils.remove(context, NEED_UP_ORDER)
}
}
}))
}
}
Binary file not shown.