修改蓝牙直播,同时获取网络轨迹的bug;新增出现闪退,5秒自动退出APP;

This commit is contained in:
yezhiqiu
2025-11-17 09:48:42 +08:00
parent 19fbe218a7
commit 27f954a8c8
14 changed files with 119 additions and 18 deletions

View File

@@ -28,9 +28,9 @@ android {
applicationId "com.abbidot.tracker" applicationId "com.abbidot.tracker"
minSdkVersion 23 minSdkVersion 23
targetSdkVersion 35 targetSdkVersion 35
versionCode 2100 versionCode 2101
// versionName "2.1.0" // versionName "2.1.1"
versionName "2.1.0-Beta1" versionName "2.1.1-Beta1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@@ -11,6 +11,7 @@ import coil.decode.GifDecoder
import coil.decode.ImageDecoderDecoder import coil.decode.ImageDecoderDecoder
import com.abbidot.baselibrary.util.AppUtils import com.abbidot.baselibrary.util.AppUtils
import com.abbidot.baselibrary.util.MMKVUtil import com.abbidot.baselibrary.util.MMKVUtil
import com.abbidot.tracker.util.CrashHandler
import com.hjq.toast.Toaster import com.hjq.toast.Toaster
import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager
import dagger.hilt.android.HiltAndroidApp import dagger.hilt.android.HiltAndroidApp
@@ -76,6 +77,8 @@ class MyApplication : Application() {
//设置全局唯一实例 //设置全局唯一实例
Coil.setImageLoader(imageLoader) Coil.setImageLoader(imageLoader)
} }
CrashHandler().init(this)
} }
/** /**

View File

@@ -48,6 +48,7 @@ import com.abbidot.tracker.util.Util
import com.abbidot.tracker.util.ViewUtil import com.abbidot.tracker.util.ViewUtil
import com.abbidot.tracker.util.bluetooth.SRBleUtil import com.abbidot.tracker.util.bluetooth.SRBleUtil
import com.abbidot.tracker.vm.ConnectionDeviceViewModel import com.abbidot.tracker.vm.ConnectionDeviceViewModel
import com.abbidot.tracker.vm.CountDownTimerViewModel
import com.abbidot.tracker.vm.DataViewModel import com.abbidot.tracker.vm.DataViewModel
import com.abbidot.tracker.vm.LogBleReportViewModel import com.abbidot.tracker.vm.LogBleReportViewModel
import com.abbidot.tracker.vm.SocketSendMessageViewModel import com.abbidot.tracker.vm.SocketSendMessageViewModel
@@ -74,6 +75,7 @@ class HomeV2Activity : BaseActivity<ActivityHomeV2Binding>(ActivityHomeV2Binding
private val mAutomaticConnectionDeviceViewModel: ConnectionDeviceViewModel by viewModels() private val mAutomaticConnectionDeviceViewModel: ConnectionDeviceViewModel by viewModels()
private val mSubscriptionViewModel: SubscriptionManageViewModel by viewModels() private val mSubscriptionViewModel: SubscriptionManageViewModel by viewModels()
private val mLogBleReportViewModel: LogBleReportViewModel by viewModels() private val mLogBleReportViewModel: LogBleReportViewModel by viewModels()
private val mCountDownTimerViewModel: CountDownTimerViewModel by viewModels()
private val mSocketSendMessageViewModel: SocketSendMessageViewModel by viewModels() private val mSocketSendMessageViewModel: SocketSendMessageViewModel by viewModels()
private var mChangePetDialog: CommonListDialog? = null private var mChangePetDialog: CommonListDialog? = null
@@ -168,6 +170,13 @@ class HomeV2Activity : BaseActivity<ActivityHomeV2Binding>(ActivityHomeV2Binding
// intent.putExtra("REBOOT", "reboot") // intent.putExtra("REBOOT", "reboot")
// startActivity(intent) // startActivity(intent)
//出现闪退,5秒退出APP
val isCrash = MMKVUtil.getBoolean(MMKVKey.isCrash, false)
if (isCrash) {
MMKVUtil.putBoolean(MMKVKey.isCrash, false)
showToast(R.string.txt_show_crash)
mCountDownTimerViewModel.startCountDown(6)
} else {
//预先加载相册,防止上传头像几千张照片加载慢 //预先加载相册,防止上传头像几千张照片加载慢
XXPermissions.with(this).permission(PermissionLists.getReadMediaImagesPermission()) XXPermissions.with(this).permission(PermissionLists.getReadMediaImagesPermission())
.request { _, allGranted -> .request { _, allGranted ->
@@ -181,6 +190,7 @@ class HomeV2Activity : BaseActivity<ActivityHomeV2Binding>(ActivityHomeV2Binding
} }
} }
} }
}
override fun liveDataObserve() { override fun liveDataObserve() {
@@ -191,6 +201,11 @@ class HomeV2Activity : BaseActivity<ActivityHomeV2Binding>(ActivityHomeV2Binding
Dispatchers.Unconfined不对协程的执行环境做任何限制协程将在调用它的线程中执行直到遇到挂起函数为止之后会在恢复执行时继续在之前的线程中执行 Dispatchers.Unconfined不对协程的执行环境做任何限制协程将在调用它的线程中执行直到遇到挂起函数为止之后会在恢复执行时继续在之前的线程中执行
*/ */
//出现闪退,5秒退出APP
mCountDownTimerViewModel.mCountDownEndLiveData.observe(this) {
finish()
System.gc()
}
//退出登录 //退出登录
XEventBus.observe(this, EventName.LogOut) { XEventBus.observe(this, EventName.LogOut) {
finish() finish()

View File

@@ -304,6 +304,7 @@ class LiveActivityV2 : BaseActivity<ActivityLiveV2Binding>(ActivityLiveV2Binding
//直播开始 //直播开始
else -> { else -> {
//直播开启后,就去获取直播轨迹 //直播开启后,就去获取直播轨迹
if (!BleManager.getInstance().isConnected(macID)) {
mMapLiveViewModel.mGetPetLivePointTimeStamp = mMapLiveViewModel.mGetPetLivePointTimeStamp =
System.currentTimeMillis() / 1000 System.currentTimeMillis() / 1000
mMapLiveViewModel.getPetLivePoint(deviceId) mMapLiveViewModel.getPetLivePoint(deviceId)
@@ -311,6 +312,7 @@ class LiveActivityV2 : BaseActivity<ActivityLiveV2Binding>(ActivityLiveV2Binding
} }
} }
} }
}
override fun onRequestError(exceptionCode: String?) { override fun onRequestError(exceptionCode: String?) {
LogUtil.e("HomeV2Activity直播开启错误onRequestError再次请求") LogUtil.e("HomeV2Activity直播开启错误onRequestError再次请求")
@@ -987,6 +989,8 @@ class LiveActivityV2 : BaseActivity<ActivityLiveV2Binding>(ActivityLiveV2Binding
ilLiveV2BluetoothFindDevice.btnLiveV2StopRadar -> { ilLiveV2BluetoothFindDevice.btnLiveV2StopRadar -> {
if (isLiveJump) { if (isLiveJump) {
isOpenSound = true
setSound()
showAndHideFindLayout() showAndHideFindLayout()
mFindBleDeviceViewModel.stopFindDevice() mFindBleDeviceViewModel.stopFindDevice()
} else { } else {

View File

@@ -0,0 +1,75 @@
package com.abbidot.tracker.util
import android.content.Context
import android.os.Process
import com.abbidot.baselibrary.constant.MMKVKey
import com.abbidot.baselibrary.util.LogUtil
import com.abbidot.baselibrary.util.MMKVUtil
/**
*Created by .yzq on 2025/11/14/周五.
* @link
* @description:
*/
class CrashHandler : Thread.UncaughtExceptionHandler {
private val mTAG = "CrashHandler"
private lateinit var mContext: Context
// private var mDefaultHandler: Thread.UncaughtExceptionHandler? = null
override fun uncaughtException(t: Thread, e: Throwable) {
LogUtil.e(mTAG, "当前进程id:" + Process.myPid())
// LogUtil.e(mTAG, "异常信息:" + Log.getStackTraceString(e))
// mDefaultHandler?.uncaughtException(t, e)
MMKVUtil.putBoolean(MMKVKey.isCrash, true)
// restartApp()
}
fun init(context: Context) {
mContext = context.applicationContext
// mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler()!!
Thread.setDefaultUncaughtExceptionHandler(this)
}
private fun restartApp() {
// val intent = mContext.packageManager.getLaunchIntentForPackage(mContext.packageName)
// if (intent != null) {
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
// mContext.startActivity(intent)
// Process.killProcess(Process.myPid())
// exitProcess(0)
// }
// val intent = mContext.packageManager.getLaunchIntentForPackage(mContext.packageName)
// intent?.apply {
// addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
// mContext.startActivity(this)
// Process.killProcess(Process.myPid())
// System.exit(0)
// }
// Process.killProcess(Process.myPid())
//
// val intent = Intent(mContext, SplashActivity::class.java)
// val restartIntent = PendingIntent.getActivity(
// mContext.applicationContext,
// 0,
// intent,
// PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_CANCEL_CURRENT
// );
// //退出程序
// val mgr =
// mContext.applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager
// // 1秒钟后重启应用
// mgr.set(
// AlarmManager.RTC, System.currentTimeMillis() + 1000, restartIntent
// )
// exitProcess(0)
}
}

View File

@@ -187,6 +187,7 @@ class SRBleUtil private constructor() {
fun openNotify( fun openNotify(
bleDevice: BleDevice, gatt: BluetoothGatt, uuid_service: String, uuid_notify: String bleDevice: BleDevice, gatt: BluetoothGatt, uuid_service: String, uuid_notify: String
) { ) {
val notifyId = uuid_notify.split("-")[0]
BleManager.getInstance() BleManager.getInstance()
.notify(bleDevice, uuid_service, uuid_notify, object : BleNotifyCallback() { .notify(bleDevice, uuid_service, uuid_notify, object : BleNotifyCallback() {
override fun onNotifySuccess() { override fun onNotifySuccess() {
@@ -204,7 +205,7 @@ class SRBleUtil private constructor() {
override fun onCharacteristicChanged(data: ByteArray?) { override fun onCharacteristicChanged(data: ByteArray?) {
val formatData = HexUtil.formatHexString(data, true) val formatData = HexUtil.formatHexString(data, true)
LogUtil.e("设备响应指令,${bleDevice.mac}->" + formatData) LogUtil.e("设备响应指令,${bleDevice.mac},$notifyId->" + formatData)
data?.apply { data?.apply {
val data0 = SRBleCmdUtil.instance.byteToInt(data[0]) val data0 = SRBleCmdUtil.instance.byteToInt(data[0])
val data1 = SRBleCmdUtil.instance.byteToInt(data[1]) val data1 = SRBleCmdUtil.instance.byteToInt(data[1])

View File

@@ -19,7 +19,6 @@ import com.clj.fastble.BleManager
import com.clj.fastble.callback.BleRssiCallback import com.clj.fastble.callback.BleRssiCallback
import com.clj.fastble.callback.BleScanCallback import com.clj.fastble.callback.BleScanCallback
import com.clj.fastble.data.BleDevice import com.clj.fastble.data.BleDevice
import com.clj.fastble.data.BleScanState
import com.clj.fastble.exception.BleException import com.clj.fastble.exception.BleException
import com.clj.fastble.scan.BleScanRuleConfig import com.clj.fastble.scan.BleScanRuleConfig
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@@ -275,10 +274,6 @@ class FindBleDeviceViewModel : ViewModel() {
fun stopFindDevice() { fun stopFindDevice() {
if (!isStartFindBleDevice) return if (!isStartFindBleDevice) return
SRBleUtil.instance.cancelBleScan("停止查找设备取消扫描蓝牙") SRBleUtil.instance.cancelBleScan("停止查找设备取消扫描蓝牙")
mSoundPool?.apply {
if (mStreamID > 0) stop(mStreamID)
release()
}
//还原手机原来的音量 //还原手机原来的音量
setVolume(mPhoneOriginalVolume) setVolume(mPhoneOriginalVolume)
isStartFindBleDevice = false isStartFindBleDevice = false
@@ -287,6 +282,10 @@ class FindBleDeviceViewModel : ViewModel() {
override fun onCleared() { override fun onCleared() {
super.onCleared() super.onCleared()
mSoundPool?.apply {
if (mStreamID > 0) stop(mStreamID)
release()
}
stopFindDevice() stopFindDevice()
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

@@ -971,5 +971,6 @@
<string name="txt_update_time">更新于:%s</string> <string name="txt_update_time">更新于:%s</string>
<string name="txt_as_low_as">低至</string> <string name="txt_as_low_as">低至</string>
<string name="txt_show_crash">APP出现异常即将退出</string>
</resources> </resources>

View File

@@ -1047,5 +1047,6 @@
<string name="txt_expiry_time">Expiry Time:</string> <string name="txt_expiry_time">Expiry Time:</string>
<string name="txt_year_care">%s Year Care</string> <string name="txt_year_care">%s Year Care</string>
<string name="txt_fence_saved">Saved. Active when online.</string> <string name="txt_fence_saved">Saved. Active when online.</string>
<string name="txt_show_crash">The program has an exception and is about to exit</string>
</resources> </resources>

View File

@@ -36,6 +36,7 @@ import androidx.annotation.StringDef
MMKVKey.OnlyGoogleMap, MMKVKey.OnlyGoogleMap,
MMKVKey.MapType, MMKVKey.MapType,
MMKVKey.ShowFence, MMKVKey.ShowFence,
MMKVKey.isCrash,
MMKVKey.Shared MMKVKey.Shared
) )
@Retention(AnnotationRetention.SOURCE) @Retention(AnnotationRetention.SOURCE)
@@ -95,5 +96,6 @@ annotation class MMKVKey {
//是否分享的 //是否分享的
const val Shared = "shared" const val Shared = "shared"
const val isCrash = "isCrash"
} }
} }