|
@@ -33,6 +33,7 @@ import androidx.navigation.ui.AppBarConfiguration;
|
|
|
import androidx.navigation.ui.NavigationUI;
|
|
|
|
|
|
import com.emato.ich.databinding.ActivityMainBinding;
|
|
|
+import com.xuexiang.xupdate.XUpdate;
|
|
|
|
|
|
import android.view.Menu;
|
|
|
import android.view.MenuItem;
|
|
@@ -261,48 +262,52 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
// 注册柜子信息
|
|
|
|
|
|
- String appVersion = BaseUtils.getAppVersion(getApplicationContext());
|
|
|
- String androidVersion = BaseUtils.getVersionName();
|
|
|
- CountDownLatch countDownLatch = new CountDownLatch(10);
|
|
|
- Cabinet cabinet = DeviceControl.queryCabinetInfo(countDownLatch);
|
|
|
- try {
|
|
|
- countDownLatch.await();
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- cabinet.setClientId(clientId);
|
|
|
- cabinet.setSoftwareVersion(appVersion);
|
|
|
- cabinet.setAndroidVersion(androidVersion);
|
|
|
- cabinet.setSoftwareType("android");
|
|
|
- cabinet.setImei(BaseUtils.getIMEI(getApplicationContext()));
|
|
|
- cabinet.setMacIpv4("111");
|
|
|
- cabinet.setMacIpv6("unknown");
|
|
|
- cabinet.setNetType("111");
|
|
|
- cabinet.setPlatType("S905");
|
|
|
- cabinet.setSim("111");
|
|
|
- cabinet.setWifiSSid("111");
|
|
|
-
|
|
|
- ObjectMapper objectMapper = JacksonUtils.objectmapper;
|
|
|
-
|
|
|
- try {
|
|
|
- String jsonData = objectMapper.writeValueAsString(cabinet);
|
|
|
- Log.i(TAG, "onCreate: jsonData===============>" + jsonData);
|
|
|
-
|
|
|
- MqttMessage message = new MqttMessage();
|
|
|
- message.setQos(1);
|
|
|
- message.setPayload(jsonData.getBytes());
|
|
|
- ichPublishClient.publish(String.format(ICHTopic.CABINET_INFO_REPORT, clientId), message);
|
|
|
- } catch (JsonProcessingException e) {
|
|
|
- Log.e(TAG, "onCreate: 解析成JSON失败!", e);
|
|
|
- }
|
|
|
+// String appVersion = BaseUtils.getAppVersion(getApplicationContext());
|
|
|
+// String androidVersion = BaseUtils.getVersionName();
|
|
|
+// CountDownLatch countDownLatch = new CountDownLatch(10);
|
|
|
+// Cabinet cabinet = DeviceControl.queryCabinetInfo(countDownLatch);
|
|
|
+// try {
|
|
|
+// countDownLatch.await();
|
|
|
+// } catch (InterruptedException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+//
|
|
|
+// cabinet.setClientId(clientId);
|
|
|
+// cabinet.setSoftwareVersion(appVersion);
|
|
|
+// cabinet.setAndroidVersion(androidVersion);
|
|
|
+// cabinet.setSoftwareType("android");
|
|
|
+// cabinet.setImei(BaseUtils.getIMEI(getApplicationContext()));
|
|
|
+// cabinet.setMacIpv4("111");
|
|
|
+// cabinet.setMacIpv6("unknown");
|
|
|
+// cabinet.setNetType("111");
|
|
|
+// cabinet.setPlatType("S905");
|
|
|
+// cabinet.setSim("111");
|
|
|
+// cabinet.setWifiSSid("111");
|
|
|
+//
|
|
|
+// ObjectMapper objectMapper = JacksonUtils.objectmapper;
|
|
|
+//
|
|
|
+// try {
|
|
|
+// String jsonData = objectMapper.writeValueAsString(cabinet);
|
|
|
+// Log.i(TAG, "onCreate: jsonData===============>" + jsonData);
|
|
|
+//
|
|
|
+// MqttMessage message = new MqttMessage();
|
|
|
+// message.setQos(1);
|
|
|
+// message.setPayload(jsonData.getBytes());
|
|
|
+// ichPublishClient.publish(String.format(ICHTopic.CABINET_INFO_REPORT, clientId), message);
|
|
|
+// } catch (JsonProcessingException e) {
|
|
|
+// Log.e(TAG, "onCreate: 解析成JSON失败!", e);
|
|
|
+// }
|
|
|
|
|
|
// TODO 更新版本监听
|
|
|
ichPublishClient.subscribe(String.format(ICHTopic.APK_UPDATE_PATH, BaseUtils.getClientId()), (msgId, msg) -> {
|
|
|
try {
|
|
|
String path = new String(msg.getPayload());
|
|
|
// 发起请求下载APK
|
|
|
- APKUpdateDownload.getInstance().downloadAPK(MainActivity.this, getApplication(), path);
|
|
|
+ XUpdate.newBuild(this)
|
|
|
+ .updateUrl(path)
|
|
|
+ .isAutoMode(true) //如果需要完全无人干预,自动更新,需要root权限【静默安装需要】
|
|
|
+ .update();
|
|
|
+// APKUpdateDownload.getInstance().downloadAPK(MainActivity.this, getApplication(), path);
|
|
|
} catch (Exception e) {
|
|
|
Log.e(TAG, "onCreate: 更新版本监听失败! ", e);
|
|
|
}
|