diff --git a/app/build.gradle b/app/build.gradle index 857d45c..5d3c80d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,9 +28,9 @@ android { applicationId "com.abbidot.tracker" minSdkVersion 23 targetSdkVersion 35 - versionCode 2100 -// versionName "2.1.0" - versionName "2.1.0-Beta1" + versionCode 2101 +// versionName "2.1.1" + versionName "2.1.1-Beta1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/abbidot/tracker/MyApplication.kt b/app/src/main/java/com/abbidot/tracker/MyApplication.kt index 933dcdd..6891e9e 100644 --- a/app/src/main/java/com/abbidot/tracker/MyApplication.kt +++ b/app/src/main/java/com/abbidot/tracker/MyApplication.kt @@ -11,6 +11,7 @@ import coil.decode.GifDecoder import coil.decode.ImageDecoderDecoder import com.abbidot.baselibrary.util.AppUtils import com.abbidot.baselibrary.util.MMKVUtil +import com.abbidot.tracker.util.CrashHandler import com.hjq.toast.Toaster import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager import dagger.hilt.android.HiltAndroidApp @@ -76,6 +77,8 @@ class MyApplication : Application() { //设置全局唯一实例 Coil.setImageLoader(imageLoader) } + + CrashHandler().init(this) } /** diff --git a/app/src/main/java/com/abbidot/tracker/ui/activity/HomeV2Activity.kt b/app/src/main/java/com/abbidot/tracker/ui/activity/HomeV2Activity.kt index fd28499..6db9e4e 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/activity/HomeV2Activity.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/activity/HomeV2Activity.kt @@ -48,6 +48,7 @@ import com.abbidot.tracker.util.Util import com.abbidot.tracker.util.ViewUtil import com.abbidot.tracker.util.bluetooth.SRBleUtil import com.abbidot.tracker.vm.ConnectionDeviceViewModel +import com.abbidot.tracker.vm.CountDownTimerViewModel import com.abbidot.tracker.vm.DataViewModel import com.abbidot.tracker.vm.LogBleReportViewModel import com.abbidot.tracker.vm.SocketSendMessageViewModel @@ -74,6 +75,7 @@ class HomeV2Activity : BaseActivity(ActivityHomeV2Binding private val mAutomaticConnectionDeviceViewModel: ConnectionDeviceViewModel by viewModels() private val mSubscriptionViewModel: SubscriptionManageViewModel by viewModels() private val mLogBleReportViewModel: LogBleReportViewModel by viewModels() + private val mCountDownTimerViewModel: CountDownTimerViewModel by viewModels() private val mSocketSendMessageViewModel: SocketSendMessageViewModel by viewModels() private var mChangePetDialog: CommonListDialog? = null @@ -168,18 +170,26 @@ class HomeV2Activity : BaseActivity(ActivityHomeV2Binding // intent.putExtra("REBOOT", "reboot") // startActivity(intent) - //预先加载相册,防止上传头像几千张照片加载慢 - XXPermissions.with(this).permission(PermissionLists.getReadMediaImagesPermission()) - .request { _, allGranted -> - if (allGranted) { - EasyPhotos.preLoad(this) + //出现闪退,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()) + .request { _, allGranted -> + if (allGranted) { + EasyPhotos.preLoad(this) // { // runOnUiThread { // showToast("相册加载完成") // } // } + } } - } + } } override fun liveDataObserve() { @@ -191,6 +201,11 @@ class HomeV2Activity : BaseActivity(ActivityHomeV2Binding Dispatchers.Unconfined‌:不对协程的执行环境做任何限制,协程将在调用它的线程中执行,直到遇到挂起函数为止,之后会在恢复执行时继续在之前的线程中执行‌ */ + //出现闪退,5秒退出APP + mCountDownTimerViewModel.mCountDownEndLiveData.observe(this) { + finish() + System.gc() + } //退出登录 XEventBus.observe(this, EventName.LogOut) { finish() diff --git a/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV2.kt b/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV2.kt index 719a419..714dbab 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV2.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV2.kt @@ -304,9 +304,11 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding //直播开始 else -> { //直播开启后,就去获取直播轨迹 - mMapLiveViewModel.mGetPetLivePointTimeStamp = - System.currentTimeMillis() / 1000 - mMapLiveViewModel.getPetLivePoint(deviceId) + if (!BleManager.getInstance().isConnected(macID)) { + mMapLiveViewModel.mGetPetLivePointTimeStamp = + System.currentTimeMillis() / 1000 + mMapLiveViewModel.getPetLivePoint(deviceId) + } } } } @@ -987,6 +989,8 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding ilLiveV2BluetoothFindDevice.btnLiveV2StopRadar -> { if (isLiveJump) { + isOpenSound = true + setSound() showAndHideFindLayout() mFindBleDeviceViewModel.stopFindDevice() } else { diff --git a/app/src/main/java/com/abbidot/tracker/util/CrashHandler.kt b/app/src/main/java/com/abbidot/tracker/util/CrashHandler.kt new file mode 100644 index 0000000..c22e979 --- /dev/null +++ b/app/src/main/java/com/abbidot/tracker/util/CrashHandler.kt @@ -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) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleUtil.kt b/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleUtil.kt index 1f2ca2d..476dae9 100644 --- a/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleUtil.kt +++ b/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleUtil.kt @@ -187,6 +187,7 @@ class SRBleUtil private constructor() { fun openNotify( bleDevice: BleDevice, gatt: BluetoothGatt, uuid_service: String, uuid_notify: String ) { + val notifyId = uuid_notify.split("-")[0] BleManager.getInstance() .notify(bleDevice, uuid_service, uuid_notify, object : BleNotifyCallback() { override fun onNotifySuccess() { @@ -204,7 +205,7 @@ class SRBleUtil private constructor() { override fun onCharacteristicChanged(data: ByteArray?) { val formatData = HexUtil.formatHexString(data, true) - LogUtil.e("设备响应指令,${bleDevice.mac}->" + formatData) + LogUtil.e("设备响应指令,${bleDevice.mac},$notifyId->" + formatData) data?.apply { val data0 = SRBleCmdUtil.instance.byteToInt(data[0]) val data1 = SRBleCmdUtil.instance.byteToInt(data[1]) diff --git a/app/src/main/java/com/abbidot/tracker/vm/FindBleDeviceViewModel.kt b/app/src/main/java/com/abbidot/tracker/vm/FindBleDeviceViewModel.kt index 90337be..b547819 100644 --- a/app/src/main/java/com/abbidot/tracker/vm/FindBleDeviceViewModel.kt +++ b/app/src/main/java/com/abbidot/tracker/vm/FindBleDeviceViewModel.kt @@ -19,7 +19,6 @@ import com.clj.fastble.BleManager import com.clj.fastble.callback.BleRssiCallback import com.clj.fastble.callback.BleScanCallback import com.clj.fastble.data.BleDevice -import com.clj.fastble.data.BleScanState import com.clj.fastble.exception.BleException import com.clj.fastble.scan.BleScanRuleConfig import kotlinx.coroutines.Dispatchers @@ -275,10 +274,6 @@ class FindBleDeviceViewModel : ViewModel() { fun stopFindDevice() { if (!isStartFindBleDevice) return SRBleUtil.instance.cancelBleScan("停止查找设备取消扫描蓝牙") - mSoundPool?.apply { - if (mStreamID > 0) stop(mStreamID) - release() - } //还原手机原来的音量 setVolume(mPhoneOriginalVolume) isStartFindBleDevice = false @@ -287,6 +282,10 @@ class FindBleDeviceViewModel : ViewModel() { override fun onCleared() { super.onCleared() + mSoundPool?.apply { + if (mStreamID > 0) stop(mStreamID) + release() + } stopFindDevice() } } \ No newline at end of file diff --git a/app/src/main/res/mipmap-xhdpi/logo_abbidot.jpg b/app/src/main/res/mipmap-xhdpi/logo_abbidot.jpg deleted file mode 100644 index 28b585b..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/logo_abbidot.jpg and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/logo_abbidot.png b/app/src/main/res/mipmap-xhdpi/logo_abbidot.png index a97961e..269cf00 100644 Binary files a/app/src/main/res/mipmap-xhdpi/logo_abbidot.png and b/app/src/main/res/mipmap-xhdpi/logo_abbidot.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/logo_abbidot.png b/app/src/main/res/mipmap-xxhdpi/logo_abbidot.png index 9a53c70..6c5097e 100644 Binary files a/app/src/main/res/mipmap-xxhdpi/logo_abbidot.png and b/app/src/main/res/mipmap-xxhdpi/logo_abbidot.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/logo_abbidot.png b/app/src/main/res/mipmap-xxxhdpi/logo_abbidot.png index a7a4d03..2437f02 100644 Binary files a/app/src/main/res/mipmap-xxxhdpi/logo_abbidot.png and b/app/src/main/res/mipmap-xxxhdpi/logo_abbidot.png differ diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index e32073f..10db7e4 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -971,5 +971,6 @@ 更新于:%s 低至 + APP出现异常,即将退出! \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b3c12f8..5250355 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1047,5 +1047,6 @@ Expiry Time: %s Year Care Saved. Active when online. + The program has an exception and is about to exit \ No newline at end of file diff --git a/baselibrary/src/main/java/com/abbidot/baselibrary/constant/MMKVKey.kt b/baselibrary/src/main/java/com/abbidot/baselibrary/constant/MMKVKey.kt index f6b9920..a30c933 100644 --- a/baselibrary/src/main/java/com/abbidot/baselibrary/constant/MMKVKey.kt +++ b/baselibrary/src/main/java/com/abbidot/baselibrary/constant/MMKVKey.kt @@ -36,6 +36,7 @@ import androidx.annotation.StringDef MMKVKey.OnlyGoogleMap, MMKVKey.MapType, MMKVKey.ShowFence, + MMKVKey.isCrash, MMKVKey.Shared ) @Retention(AnnotationRetention.SOURCE) @@ -95,5 +96,6 @@ annotation class MMKVKey { //是否分享的 const val Shared = "shared" + const val isCrash = "isCrash" } }