|
@@ -27,10 +27,13 @@ import android.widget.TextView
|
27
|
27
|
import android.widget.Toast
|
28
|
28
|
import androidx.activity.addCallback
|
29
|
29
|
import androidx.lifecycle.lifecycleScope
|
30
|
|
-import androidx.lifecycle.viewModelScope
|
31
|
30
|
import androidx.recyclerview.widget.GridLayoutManager
|
32
|
31
|
import androidx.work.PeriodicWorkRequest
|
33
|
32
|
import androidx.work.WorkManager
|
|
33
|
+import com.baidu.location.BDAbstractLocationListener
|
|
34
|
+import com.baidu.location.BDLocation
|
|
35
|
+import com.baidu.location.LocationClient
|
|
36
|
+import com.baidu.location.LocationClientOption
|
34
|
37
|
import com.bumptech.glide.Glide
|
35
|
38
|
import com.bumptech.glide.request.target.CustomViewTarget
|
36
|
39
|
import com.bumptech.glide.request.transition.Transition
|
|
@@ -56,6 +59,7 @@ import com.xhly.corelib.utils.SystemUtil
|
56
|
59
|
import com.xhly.manageapp.AppAdapter
|
57
|
60
|
import com.xhly.manageapp.ManageApplication
|
58
|
61
|
import com.xhly.manageapp.bean.EventLog
|
|
62
|
+import com.xhly.manageapp.bean.PadLocationConst
|
59
|
63
|
import com.xhly.manageapp.bean.SocketMsgBean
|
60
|
64
|
import com.xhly.manageapp.bean.app.AppInstallBean
|
61
|
65
|
import com.xhly.manageapp.bean.app.AppModel
|
|
@@ -73,13 +77,11 @@ import com.xhly.manageapp.service.websocket.AppSocket
|
73
|
77
|
import com.xhly.manageapp.ui.ManageActivity
|
74
|
78
|
import com.xhly.manageapp.ui.login.activity.LoginActivity
|
75
|
79
|
import com.xhly.manageapp.ui.main.viewmodel.MainViewModel
|
76
|
|
-import com.xhly.manageapp.utils.AppDownLoadUtils
|
77
|
80
|
import com.xhly.manageapp.utils.CurrentAppSharedPreferencesUtils
|
78
|
81
|
import com.xhly.manageapp.utils.CustomAppUtils
|
79
|
82
|
import com.xhly.manageapp.utils.InstallUtils
|
80
|
83
|
import com.xhly.manageapp.utils.PadInfoUtils
|
81
|
84
|
import com.xhly.manageapp.utils.StrategyUtils
|
82
|
|
-import com.xhly.manageapp.utils.ZJAPPUtils
|
83
|
85
|
import com.xhly.manageapp.workmanager.TimingWorker
|
84
|
86
|
import kotlinx.coroutines.Dispatchers
|
85
|
87
|
import kotlinx.coroutines.launch
|
|
@@ -116,6 +118,8 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
116
|
118
|
|
117
|
119
|
//标记是否可以点击啊
|
118
|
120
|
private var canClickFlag=false
|
|
121
|
+ //百度定位
|
|
122
|
+ private var locationClient:LocationClient?=null
|
119
|
123
|
override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
|
120
|
124
|
|
121
|
125
|
@SuppressLint("CheckResult")
|
|
@@ -405,6 +409,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
405
|
409
|
}
|
406
|
410
|
}
|
407
|
411
|
}
|
|
412
|
+ getLocation()
|
408
|
413
|
startWorkManager()
|
409
|
414
|
lastTimeLong=System.currentTimeMillis()
|
410
|
415
|
updateAllStrategy()
|
|
@@ -624,7 +629,6 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
624
|
629
|
}
|
625
|
630
|
updatePadInfo()
|
626
|
631
|
updateMcApp()
|
627
|
|
- getLocation()
|
628
|
632
|
val appVersionCode = SystemUtil.getAppVersionCode(this, packageName)
|
629
|
633
|
val appVersionName =SystemUtil.getAppVersionName(this,packageName)
|
630
|
634
|
mBinding.versionTv.text="版本 v${appVersionName} (Build ${appVersionCode})"
|
|
@@ -770,14 +774,13 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
770
|
774
|
viewModel.updateMcApp(updateBean)
|
771
|
775
|
}
|
772
|
776
|
} catch (e: Exception) {
|
773
|
|
-
|
|
777
|
+ LogShow("用户信息不存在")
|
774
|
778
|
}
|
775
|
779
|
}
|
776
|
780
|
|
777
|
781
|
@SuppressLint("CheckResult")
|
778
|
782
|
private fun getLocation() {
|
779
|
783
|
val rxPermissions = RxPermissions(this)
|
780
|
|
- // Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS
|
781
|
784
|
rxPermissions.request(
|
782
|
785
|
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION
|
783
|
786
|
).subscribe({
|
|
@@ -785,19 +788,73 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
785
|
788
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
786
|
789
|
rxPermissions.request(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
787
|
790
|
.subscribe {
|
788
|
|
- SystemUtil.getLocation(this)
|
|
791
|
+ //SystemUtil.getLocation(this)
|
|
792
|
+ baiduLocation()
|
789
|
793
|
}
|
790
|
794
|
} else {
|
791
|
|
- SystemUtil.getLocation(this)
|
|
795
|
+ //SystemUtil.getLocation(this)
|
|
796
|
+ baiduLocation()
|
792
|
797
|
}
|
793
|
798
|
} else {
|
|
799
|
+ baiduLocation()
|
794
|
800
|
LogShow("没有权限")
|
795
|
801
|
}
|
796
|
802
|
}, {
|
|
803
|
+ baiduLocation()
|
797
|
804
|
LogShow("没有权限" + it.message)
|
798
|
805
|
})
|
799
|
806
|
}
|
800
|
807
|
|
|
808
|
+ private fun baiduLocation(){
|
|
809
|
+ LocationClient.setAgreePrivacy(true)
|
|
810
|
+ locationClient = LocationClient(application)
|
|
811
|
+ val option = LocationClientOption()
|
|
812
|
+ option.locationMode=LocationClientOption.LocationMode.Hight_Accuracy
|
|
813
|
+ option.setCoorType("bd09ll")
|
|
814
|
+ option.setFirstLocType(LocationClientOption.FirstLocType.ACCURACY_IN_FIRST_LOC)
|
|
815
|
+ option.setScanSpan(1000*60*5)
|
|
816
|
+ option.setOpenGnss(true)
|
|
817
|
+ option.setLocationNotify(true)
|
|
818
|
+ option.setEnableSimulateGnss(false)
|
|
819
|
+ option.setNeedNewVersionRgc(true)
|
|
820
|
+ option.setIsNeedAddress(true)
|
|
821
|
+ locationClient?.locOption=option
|
|
822
|
+ locationClient?.registerLocationListener(object :BDAbstractLocationListener(){
|
|
823
|
+ override fun onReceiveLocation(bdLocation: BDLocation) {
|
|
824
|
+ //此处的BDLocation为定位结果信息类,通过它的各种get方法可获取定位相关的全部结果
|
|
825
|
+ val latitude: Double = bdLocation.getLatitude() //获取纬度信息
|
|
826
|
+
|
|
827
|
+ val longitude: Double = bdLocation.getLongitude() //获取经度信息
|
|
828
|
+ val addrStr = bdLocation.addrStr
|
|
829
|
+ val location = PadLocationConst.currentLocation
|
|
830
|
+ location.lat=latitude
|
|
831
|
+ location.lon=longitude
|
|
832
|
+ location.address=addrStr
|
|
833
|
+ try {
|
|
834
|
+ val lastLocation = PadLocationConst.lastLocation
|
|
835
|
+ if (location.lat!=null&&location.lon!=null&&(lastLocation.lon!=location.lon&&lastLocation.lat!=location.lat)){
|
|
836
|
+ lastLocation.lat=location.lat
|
|
837
|
+ lastLocation.lon=location.lon
|
|
838
|
+ ManageApplication.getDeviceInfo()?.let {
|
|
839
|
+ location.sn=it
|
|
840
|
+ }
|
|
841
|
+ userBean?.let {
|
|
842
|
+ location.userid=it.userid
|
|
843
|
+ }
|
|
844
|
+ viewModel.postPadLocation((location))
|
|
845
|
+ LogShow("真没有位置")
|
|
846
|
+ }else{
|
|
847
|
+ LogShow("没有位置")
|
|
848
|
+ }
|
|
849
|
+ }catch (e:Exception){
|
|
850
|
+ LogShow("没有位置问题"+e.toString())
|
|
851
|
+ }
|
|
852
|
+ }
|
|
853
|
+
|
|
854
|
+ })
|
|
855
|
+ locationClient?.start()
|
|
856
|
+ }
|
|
857
|
+
|
801
|
858
|
private fun useTimeStrategy() {
|
802
|
859
|
//获得sputils中的平板锁定策略
|
803
|
860
|
try {
|
|
@@ -1306,6 +1363,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
1306
|
1363
|
timer?.cancel()
|
1307
|
1364
|
timer = null
|
1308
|
1365
|
}
|
|
1366
|
+ locationClient?.stop()
|
1309
|
1367
|
AppSocket.onDestroy()
|
1310
|
1368
|
DownLoadUtils.removeCallback(this)
|
1311
|
1369
|
mMyInstallReceiver?.let {
|