|
@@ -52,9 +52,12 @@ import com.naz.sdkdemo.base.BaseActivity;
|
|
|
import com.naz.sdkdemo.bean.PrintModule;
|
|
|
import com.naz.sdkdemo.bean.PrintModule2;
|
|
|
import com.naz.sdkdemo.bean.PrintModule3;
|
|
|
+import com.naz.sdkdemo.bean.VersionBean;
|
|
|
import com.naz.sdkdemo.comm.Constants;
|
|
|
+import com.naz.sdkdemo.dialog.VersionUpdateDialog;
|
|
|
import com.naz.sdkdemo.helper.SerialPortManager;
|
|
|
import com.naz.sdkdemo.http.ApiHelper;
|
|
|
+import com.naz.sdkdemo.utils.DownloadService;
|
|
|
import com.naz.sdkdemo.utils.FastClickUtil;
|
|
|
import com.naz.sdkdemo.utils.MyTools;
|
|
|
import com.naz.sdkdemo.utils.NetworkSpeedTest;
|
|
@@ -119,7 +122,8 @@ import android_serialport_api.SerialPortFinder;
|
|
|
public class MainActivity extends BaseActivity {
|
|
|
private final String TAG = "HomeActivity";
|
|
|
private final String TAG2 = "BleBle";
|
|
|
-
|
|
|
+ private static final int REQUEST_CODE_OPEN_GPS = 1;
|
|
|
+ private static final int REQUEST_CODE_PERMISSION_LOCATION = 2;
|
|
|
private WebView mWebView;
|
|
|
private LinearLayout ll_nonet;
|
|
|
private LinearLayout ll_web;
|
|
@@ -155,6 +159,8 @@ public class MainActivity extends BaseActivity {
|
|
|
String networkTestUrl = "https://clouddevice.qingyaokeji.com/api/androidVersion";
|
|
|
Handler sendCommandhandler = new Handler();
|
|
|
|
|
|
+ private DownloadService downloadService = new DownloadService();
|
|
|
+
|
|
|
@Override
|
|
|
protected int getLayoutResId() {
|
|
|
return R.layout.activity_home_web;
|
|
@@ -397,7 +403,7 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
|
Log.e("------->","-------->"+UserCache.getSerialName());
|
|
|
}
|
|
|
- // -------------------------------------WebInterface相关方法开始----------------------------
|
|
|
+ //region -------------------------------------WebInterface相关方法开始----------------------------
|
|
|
String mUrl = "http://192.168.0.133:8082";
|
|
|
private void checkNet() {
|
|
|
if (!MyTools.isNetworkAvailable(getApplicationContext())) {
|
|
@@ -424,6 +430,17 @@ public class MainActivity extends BaseActivity {
|
|
|
private class AndroidInterface {
|
|
|
|
|
|
@JavascriptInterface
|
|
|
+ public void checkVersionUpdate() {
|
|
|
+ try {
|
|
|
+ Log.e(TAG, "checkVersionUpdate");
|
|
|
+ toCheckVersionUpdate();
|
|
|
+ }catch (Exception e) {
|
|
|
+ XToast.showToast(e.getMessage());
|
|
|
+ uploadLogMessage(Arrays.toString(e.getStackTrace()) + "------>>" + e.getMessage(), "exception");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
public void swiftNetwork() {
|
|
|
try {
|
|
|
Log.e(TAG, "swiftNetwork");
|
|
@@ -744,10 +761,9 @@ public class MainActivity extends BaseActivity {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // -------------------------------------WebInterface相关方法结束----------------------------
|
|
|
+ //endregion -------------------------------------WebInterface相关方法结束----------------------------
|
|
|
|
|
|
- // -------------------------------------获取usb口状态开始-----------------------------------
|
|
|
- // todo 暂时放在这里
|
|
|
+ //region -------------------------------------清除缓存开始-----------------------------------
|
|
|
private void toRefreshData() {
|
|
|
try {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // 清除cookie
|
|
@@ -788,7 +804,9 @@ public class MainActivity extends BaseActivity {
|
|
|
}
|
|
|
return deletedFiles;
|
|
|
}
|
|
|
+ //endregion -------------------------------------清除缓存结束-----------------------------------
|
|
|
|
|
|
+ //region -------------------------------------获取usb口状态开始-----------------------------------
|
|
|
private List<String> sendCommands = new ArrayList<String>(){
|
|
|
{
|
|
|
add("07C60408008A09FE94");
|
|
@@ -973,9 +991,9 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
|
|
|
|
}
|
|
|
- // -------------------------------------获取usb口状态结束---------------------------------
|
|
|
+ //endregion -------------------------------------获取usb口状态结束---------------------------------
|
|
|
|
|
|
- // -------------------------------------拍照相关方法结束----------------------------------
|
|
|
+ //region -------------------------------------拍照相关方法结束----------------------------------
|
|
|
int retryCount = 0;
|
|
|
int maxRetries = 10;
|
|
|
private void toCloseCamera() {
|
|
@@ -1199,9 +1217,9 @@ public class MainActivity extends BaseActivity {
|
|
|
File imageFile = new File(picturesDir, imageName);
|
|
|
return imageFile.exists() ? imageFile.getAbsolutePath() :"";
|
|
|
}
|
|
|
- // -------------------------------------拍照相关方法结束---------------------------------
|
|
|
+ //endregion -------------------------------------拍照相关方法结束---------------------------------
|
|
|
|
|
|
- // -------------------------------------打印相关方法开始---------------------------------
|
|
|
+ //region -------------------------------------打印相关方法开始---------------------------------
|
|
|
static int mPot = 8;//mm转像素8倍
|
|
|
static int mWFont = 24;//字体宽度
|
|
|
static int mHFont = 24;//字体高度
|
|
@@ -1602,9 +1620,9 @@ public class MainActivity extends BaseActivity {
|
|
|
}
|
|
|
return isChinese;
|
|
|
}
|
|
|
- // -------------------------------------------------打印相关方法结束-----------------------------------
|
|
|
+ //endregion -------------------------------------------------打印相关方法结束-----------------------------------
|
|
|
|
|
|
- // -------------------------------------------------蓝牙相关方法开始-----------------------------------
|
|
|
+ //region -------------------------------------------------蓝牙相关方法开始-----------------------------------
|
|
|
//关闭蓝牙扫码器
|
|
|
BleDevice mBleDevice;
|
|
|
BluetoothGattCharacteristic mCharacteristic;
|
|
@@ -1636,6 +1654,68 @@ public class MainActivity extends BaseActivity {
|
|
|
BleManager.getInstance().initScanRule(scanRuleConfig);
|
|
|
}
|
|
|
|
|
|
+ private void checkPermissions(String name) {
|
|
|
+ bleName = name;
|
|
|
+ BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
|
+ if (!bluetoothAdapter.isEnabled()) {
|
|
|
+ Toast.makeText(this, getString(R.string.please_open_blue), Toast.LENGTH_LONG).show();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
|
|
|
+ List<String> permissionDeniedList = new ArrayList<>();
|
|
|
+ for (String permission : permissions) {
|
|
|
+ int permissionCheck = ContextCompat.checkSelfPermission(this, permission);
|
|
|
+ if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
|
|
|
+ onPermissionGranted(permission);
|
|
|
+ } else {
|
|
|
+ permissionDeniedList.add(permission);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!permissionDeniedList.isEmpty()) {
|
|
|
+ Log.e("------->","----->checkPermissions permissionDeniedList="+permissionDeniedList);
|
|
|
+ String[] deniedPermissions = permissionDeniedList.toArray(new String[permissionDeniedList.size()]);
|
|
|
+ ActivityCompat.requestPermissions(this, deniedPermissions, REQUEST_CODE_PERMISSION_LOCATION);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void onPermissionGranted(String permission) {
|
|
|
+ Log.e("------->","----->onPermissionGranted permission="+permission);
|
|
|
+ switch (permission) {
|
|
|
+ case Manifest.permission.ACCESS_FINE_LOCATION:
|
|
|
+ setScanRule();
|
|
|
+ startScan(bleName);
|
|
|
+// Log.e("------->","----->checkGPSIsOpen="+checkGPSIsOpen());
|
|
|
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !checkGPSIsOpen()) {
|
|
|
+// new AlertDialog.Builder(this)
|
|
|
+// .setTitle(R.string.notifyTitle)
|
|
|
+// .setMessage(R.string.gpsNotifyMsg)
|
|
|
+// .setNegativeButton(R.string.cancel,
|
|
|
+// new DialogInterface.OnClickListener() {
|
|
|
+// @Override
|
|
|
+// public void onClick(DialogInterface dialog, int which) {
|
|
|
+// finish();
|
|
|
+// }
|
|
|
+// })
|
|
|
+// .setPositiveButton(R.string.setting,
|
|
|
+// new DialogInterface.OnClickListener() {
|
|
|
+// @Override
|
|
|
+// public void onClick(DialogInterface dialog, int which) {
|
|
|
+// Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
|
|
+// startActivityForResult(intent, REQUEST_CODE_OPEN_GPS);
|
|
|
+// }
|
|
|
+// })
|
|
|
+//
|
|
|
+// .setCancelable(false)
|
|
|
+// .show();
|
|
|
+// } else {
|
|
|
+// setScanRule();
|
|
|
+// startScan(bleName);
|
|
|
+// }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//开始蓝牙扫码器
|
|
|
private void startScan(String name) {
|
|
|
// Toast.makeText(MainActivity.this, "开始连接", Toast.LENGTH_SHORT).show();
|
|
@@ -1844,9 +1924,7 @@ public class MainActivity extends BaseActivity {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- // --------------------------蓝牙相关方法结束--------------------------
|
|
|
|
|
|
- // --------------------------打印机相关方法结束--------------------------
|
|
|
public String hexStringToGbk(String hexString) {
|
|
|
byte[] bytes = new byte[hexString.length() / 2];
|
|
|
for (int i = 0; i < hexString.length(); i += 2) {
|
|
@@ -1861,7 +1939,9 @@ public class MainActivity extends BaseActivity {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
+ //endregion --------------------------蓝牙相关方法结束--------------------------
|
|
|
|
|
|
+ // region --------------------------打印机相关方法开始--------------------------
|
|
|
IDeviceConnection curConnect = null;
|
|
|
private void connectUSB(String pathName){
|
|
|
if (curConnect!=null){
|
|
@@ -1888,9 +1968,9 @@ public class MainActivity extends BaseActivity {
|
|
|
curConnect.close();
|
|
|
}
|
|
|
}
|
|
|
- // --------------------------打印机相关方法结束--------------------------
|
|
|
+ // endregion --------------------------打印机相关方法结束--------------------------
|
|
|
|
|
|
- // --------------------------灯相关的方法开始----------------------------
|
|
|
+ // region --------------------------灯相关的方法开始----------------------------
|
|
|
private IConnectListener connectListener = new IConnectListener() {
|
|
|
@Override
|
|
|
public void onStatus(int code, String connInfo, String msg) {
|
|
@@ -1971,7 +2051,7 @@ public class MainActivity extends BaseActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // ------------------------------灯相关的方法结束--------------------------------------
|
|
|
+ //endregion ------------------------------灯相关的方法结束--------------------------------------
|
|
|
|
|
|
// region-----------------------------切换网络开始----------------------
|
|
|
private void toSwiftNetwork() {
|
|
@@ -2155,7 +2235,261 @@ public class MainActivity extends BaseActivity {
|
|
|
}
|
|
|
// endregion-----------------------------切换网络结束-----------------------
|
|
|
|
|
|
- // ------------------------------连接及断开除灯之外的其他串口的相关方法开始------------------
|
|
|
+ // region -----------------------------大小版本更新开始----------------------
|
|
|
+ private void toCheckVersionUpdate() {
|
|
|
+ ApiHelper.versionInfoList(this, 1, "sbj",(code, msg, data) -> {
|
|
|
+ // 获取稳定的版本号
|
|
|
+ ApiHelper.stableVersionInfo(this, "androidT", (code2, msg2, data2) -> {
|
|
|
+ // 获取版本列表
|
|
|
+ List<VersionBean> versionBeanList = new ArrayList<>();
|
|
|
+ if(data instanceof List) {
|
|
|
+ List<?> content = (ArrayList<?>) data;
|
|
|
+ for (Object o : content) {
|
|
|
+ VersionBean item = (VersionBean) o;
|
|
|
+ if(item.type.equals("1")) {
|
|
|
+ versionBeanList.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 对返回的apk列表信息进行数据解析
|
|
|
+ versionBeanList = parseVersionInfo(versionBeanList);
|
|
|
+ Log.i(TAG, "checkVersionUpdate: " + JSONObject.toJSONString(versionBeanList));
|
|
|
+ // 当前apk的版本
|
|
|
+ String currentVersion = AppConfig.APP_VERSION_CODE;
|
|
|
+ Log.i(TAG, "currentVersion: " + currentVersion);
|
|
|
+ String[] currentVersionSplit = currentVersion.split("[.]");
|
|
|
+ if(currentVersionSplit == null || currentVersionSplit.length != 3) {
|
|
|
+ XToast.showToast("当前版本格式解析错误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 指定的apk版本
|
|
|
+ String publicVersion = "";
|
|
|
+ if(data2 instanceof VersionBean) {
|
|
|
+ VersionBean item = (VersionBean) data2;
|
|
|
+ publicVersion = item.version;
|
|
|
+ }
|
|
|
+ Log.i(TAG, "publicVersion: " + currentVersion);
|
|
|
+ // 从更新列表中筛选出指定的apk版本
|
|
|
+ VersionBean specifyVersion = null;
|
|
|
+ for (VersionBean bean : versionBeanList) {
|
|
|
+ // 判断是否为指定的apk生产版本版本
|
|
|
+ if(bean.versionCode.equals(publicVersion) && bean.type.equals("1")) {
|
|
|
+ specifyVersion = bean;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(specifyVersion == null) {
|
|
|
+ XToast.showToast("未找到指定版本");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(specifyVersion != null && specifyVersion.checkExtraFields()) {
|
|
|
+ // 将本地的版本与指定的apk版本进行比对
|
|
|
+ // 先进行大版本更新
|
|
|
+ if (currentVersionSplit[0].compareTo(specifyVersion.bigVersion) < 0) {
|
|
|
+ // 如果当前版本的大版本比较指定的大版本小,那么应该自动更新
|
|
|
+ loadingLabel = "正在更新版本中";
|
|
|
+ loadingDetailLabel = "请稍候";
|
|
|
+ showLoading();
|
|
|
+ downloadService.downloadApk(MainActivity.this, specifyVersion.load);
|
|
|
+ } else if (currentVersionSplit[0].equals(specifyVersion.bigVersion)) {
|
|
|
+ String noLongerVersion = SPUtils.getString(Constants.IS_SHOW_VERSION_UPDATE_DIALOG);
|
|
|
+ if (!noLongerVersion.equals(specifyVersion.versionCode)) {
|
|
|
+ // 如果大版本相同则判断小版本
|
|
|
+ if (currentVersionSplit[2].compareTo(specifyVersion.smallVersion) < 0) {
|
|
|
+ // 弹出版本更新弹窗
|
|
|
+ VersionBean finalSpecifyVersion = specifyVersion;
|
|
|
+ VersionUpdateDialog dialog = new VersionUpdateDialog(this, new VersionUpdateDialog.OnBtnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void OnCommitClickListener(VersionUpdateDialog dialog, View clickView) {
|
|
|
+ loadingLabel = "正在更新版本中";
|
|
|
+ loadingDetailLabel = "请稍候";
|
|
|
+ showLoading();
|
|
|
+ downloadService.downloadApk(MainActivity.this, finalSpecifyVersion.load);
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void OnCloseListener(VersionUpdateDialog dialog, View clickView) {
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void OnNoLongerListener(VersionUpdateDialog dialog, View clickView) {
|
|
|
+ // 记录下次不再提示的版本的版本号
|
|
|
+ // 该版本是否点了不再提醒
|
|
|
+ SPUtils.setString(Constants.IS_SHOW_VERSION_UPDATE_DIALOG, finalSpecifyVersion.versionCode);
|
|
|
+ // 当下次的大小版本大于这个版本的时候依旧会提示
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ }, "有新版本可以更新: " + currentVersion + " --> " + publicVersion + "\n" + specifyVersion.remark, false, "立即更新");
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ XToast.showToast("目标版本信息解析错误");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+// // TODO 测试代码
|
|
|
+// // 当前apk的版本
|
|
|
+// String currentVersion = "3.24.0906";
|
|
|
+// String[] currentVersionSplit = currentVersion.split("[.]");
|
|
|
+// if(currentVersionSplit == null || currentVersionSplit.length != 3) {
|
|
|
+// XToast.showToast("当前版本格式解析错误");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// // 指定的apk版本
|
|
|
+// String publicVersion = "3.24.0908";
|
|
|
+// // 可下载的apk列表
|
|
|
+// List<VersionBean> beanArrayList = new ArrayList<>();
|
|
|
+// VersionBean versionBean = new VersionBean();
|
|
|
+// versionBean.load = "https://t9.qingyaokeji.com/dwy/updateprod0906.apk";
|
|
|
+// versionBean.remark = "更新文案";
|
|
|
+// versionBean.type = "1";
|
|
|
+// versionBean.version = "测试包-3.24.0908";
|
|
|
+// beanArrayList.add(versionBean);
|
|
|
+// // 对返回的apk列表信息进行数据解析
|
|
|
+// List<VersionBean> versionBeanList = parseVersionInfo(beanArrayList);
|
|
|
+// // 从更新列表中筛选出指定的apk版本
|
|
|
+// VersionBean specifyVersion = null;
|
|
|
+// for (VersionBean bean : versionBeanList) {
|
|
|
+// // 判断是否为指定的apk生产版本版本
|
|
|
+// if(bean.versionCode.equals(publicVersion) && bean.type.equals("1")) {
|
|
|
+// specifyVersion = bean;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if(specifyVersion == null) {
|
|
|
+// XToast.showToast("未找到指定版本");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// // 找到了指定版本并且数据解析正确
|
|
|
+// if(specifyVersion != null && specifyVersion.checkExtraFields()) {
|
|
|
+// // 将本地的版本与指定的apk版本进行比对
|
|
|
+// // 先进行大版本更新
|
|
|
+// if(currentVersionSplit[0].compareTo(specifyVersion.bigVersion) < 0) {
|
|
|
+// // 如果当前版本的大版本比较指定的大版本小,那么应该自动更新
|
|
|
+// downloadService.downloadApk(NewMainActivity.this, specifyVersion.load);
|
|
|
+// } else if(currentVersionSplit[0].equals(specifyVersion.bigVersion)) {
|
|
|
+// String noLongerVersion = SPUtils.getString(Constants.IS_SHOW_VERSION_UPDATE_DIALOG);
|
|
|
+// if(!noLongerVersion.equals(specifyVersion.versionCode)) {
|
|
|
+// // 如果大版本相同则判断小版本
|
|
|
+// if(currentVersionSplit[2].compareTo(specifyVersion.smallVersion) < 0) {
|
|
|
+// // 弹出版本更新弹窗
|
|
|
+// VersionBean finalSpecifyVersion = specifyVersion;
|
|
|
+// VersionUpdateDialog dialog = new VersionUpdateDialog(this, new VersionUpdateDialog.OnBtnClickListener() {
|
|
|
+// @Override
|
|
|
+// public void OnCommitClickListener(VersionUpdateDialog dialog, View clickView) {
|
|
|
+// loadingLabel = "正在下载中";
|
|
|
+// loadingDetailLabel = "请稍候";
|
|
|
+// showLoading();
|
|
|
+// downloadService.downloadApk(NewMainActivity.this, finalSpecifyVersion.load);
|
|
|
+// dialog.dismiss();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void OnCloseListener(VersionUpdateDialog dialog, View clickView) {
|
|
|
+// dialog.dismiss();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void OnNoLongerListener(VersionUpdateDialog dialog, View clickView) {
|
|
|
+// // 记录下次不再提示的版本的版本号
|
|
|
+// // 该版本是否点了不再提醒
|
|
|
+// SPUtils.setString(Constants.IS_SHOW_VERSION_UPDATE_DIALOG, finalSpecifyVersion.versionCode);
|
|
|
+// // 当下次的大小版本大于这个版本的时候依旧会提示
|
|
|
+// dialog.dismiss();
|
|
|
+// }
|
|
|
+// }, specifyVersion.remark, false,"立即更新");
|
|
|
+// dialog.show();
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// // 正式包开启更新检查
|
|
|
+// String flag = AppConfig.APP_VERSION.contains("正式包")? "1" : "0";
|
|
|
+// String prefix = AppConfig.APP_VERSION.contains("正式包")? "正式包-" : "测试包-";
|
|
|
+// // 获取版本列表
|
|
|
+// List<VersionBean> versionBeanList = new ArrayList<>();
|
|
|
+// ApiHelper.versionInfoList(this, 1, (code, msg, data) -> {
|
|
|
+// // 保存版本信息
|
|
|
+// if(data instanceof List) {
|
|
|
+// List<?> content = (ArrayList<?>) data;
|
|
|
+// for (Object o : content) {
|
|
|
+// VersionBean item = (VersionBean) o;
|
|
|
+// if(!AppConfig.APP_VERSION.contains(item.version) && item.type.equals(flag)) {
|
|
|
+// versionBeanList.add(item);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
+// versionBeanList.sort(new Comparator<VersionBean>() {
|
|
|
+// @Override
|
|
|
+// public int compare(VersionBean v1, VersionBean v2) {
|
|
|
+// return v2.version.compareTo(v1.version);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }
|
|
|
+// // 获取最新的版本
|
|
|
+// if(versionBeanList.size() > 0) {
|
|
|
+// VersionBean latestVersion = versionBeanList.get(0);
|
|
|
+// // 将最新的版本和当前的版本进行比较
|
|
|
+// String latestVersionName = latestVersion.version.replace(prefix, "");
|
|
|
+// if(AppConfig.APP_VERSION_CODE.compareTo(latestVersionName) < 0) {
|
|
|
+// // 如果线上版本大于当前版本,则提示更新
|
|
|
+// SimpleDialog dialog = new SimpleDialog(this, new SimpleDialog.OnBtnClickListener() {
|
|
|
+// @Override
|
|
|
+// public void OnCommitClickListener(SimpleDialog dialog, View clickView) {
|
|
|
+// loadingLabel = "正在下载中";
|
|
|
+// loadingDetailLabel = "请稍候";
|
|
|
+// showLoading();
|
|
|
+// downloadService.downloadApk(NewMainActivity.this, latestVersion.load);
|
|
|
+// dialog.dismiss();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void OnCloseListener(SimpleDialog dialog, View clickView) {
|
|
|
+//
|
|
|
+// }
|
|
|
+// }, latestVersion.remark, false,"立即更新");
|
|
|
+// dialog.show();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
+ }
|
|
|
+ private List<VersionBean> parseVersionInfo(List<VersionBean> beanArrayList) {
|
|
|
+ for (VersionBean versionBean : beanArrayList) {
|
|
|
+ try {
|
|
|
+ String[] versionInfo = versionBean.version.split("-");
|
|
|
+ // 提取版本名称
|
|
|
+ String versionName = versionInfo[0];
|
|
|
+ versionBean.versionName = versionName;
|
|
|
+ // 提取版本号
|
|
|
+ String versionCode = versionInfo[1];
|
|
|
+ versionBean.versionCode = versionCode;
|
|
|
+ // 提取大小版本
|
|
|
+ String[] versionCodeSplit = versionCode.split("[.]");
|
|
|
+ versionBean.bigVersion = versionCodeSplit[0];
|
|
|
+ versionBean.middleVersion = versionCodeSplit[1];
|
|
|
+ versionBean.smallVersion = versionCodeSplit[2];
|
|
|
+ }catch (Exception e){
|
|
|
+ versionBean.clearExtraFields();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return beanArrayList;
|
|
|
+ }
|
|
|
+ // endregion -----------------------------大小版本更新结束----------------------
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //region ------------------------------连接及断开除灯之外的其他串口的相关方法开始------------------
|
|
|
private List<SerialPortManager> mPortList = new ArrayList<>();
|
|
|
private void toConnectPort(String name){
|
|
|
Log.i("===","------->toConnectPort name="+name);
|
|
@@ -2248,7 +2582,7 @@ public class MainActivity extends BaseActivity {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // ------------------------------连接及断开除灯之外的其他串口的相关方法结束------------------
|
|
|
+ //endregion ------------------------------连接及断开除灯之外的其他串口的相关方法结束------------------
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
@@ -2261,6 +2595,12 @@ public class MainActivity extends BaseActivity {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ toCheckVersionUpdate();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
if (requestCode == REQUEST_CODE_OPEN_GPS) {
|
|
@@ -2270,7 +2610,6 @@ public class MainActivity extends BaseActivity {
|
|
|
// }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
public void onBackPressed() {
|
|
|
if(cameraIsOpening) {
|
|
@@ -2281,70 +2620,6 @@ public class MainActivity extends BaseActivity {
|
|
|
super.onBackPressed();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private static final int REQUEST_CODE_OPEN_GPS = 1;
|
|
|
- private static final int REQUEST_CODE_PERMISSION_LOCATION = 2;
|
|
|
- private void checkPermissions(String name) {
|
|
|
- bleName = name;
|
|
|
- BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
|
- if (!bluetoothAdapter.isEnabled()) {
|
|
|
- Toast.makeText(this, getString(R.string.please_open_blue), Toast.LENGTH_LONG).show();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
|
|
|
- List<String> permissionDeniedList = new ArrayList<>();
|
|
|
- for (String permission : permissions) {
|
|
|
- int permissionCheck = ContextCompat.checkSelfPermission(this, permission);
|
|
|
- if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
|
|
|
- onPermissionGranted(permission);
|
|
|
- } else {
|
|
|
- permissionDeniedList.add(permission);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!permissionDeniedList.isEmpty()) {
|
|
|
- Log.e("------->","----->checkPermissions permissionDeniedList="+permissionDeniedList);
|
|
|
- String[] deniedPermissions = permissionDeniedList.toArray(new String[permissionDeniedList.size()]);
|
|
|
- ActivityCompat.requestPermissions(this, deniedPermissions, REQUEST_CODE_PERMISSION_LOCATION);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void onPermissionGranted(String permission) {
|
|
|
- Log.e("------->","----->onPermissionGranted permission="+permission);
|
|
|
- switch (permission) {
|
|
|
- case Manifest.permission.ACCESS_FINE_LOCATION:
|
|
|
- setScanRule();
|
|
|
- startScan(bleName);
|
|
|
-// Log.e("------->","----->checkGPSIsOpen="+checkGPSIsOpen());
|
|
|
-// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !checkGPSIsOpen()) {
|
|
|
-// new AlertDialog.Builder(this)
|
|
|
-// .setTitle(R.string.notifyTitle)
|
|
|
-// .setMessage(R.string.gpsNotifyMsg)
|
|
|
-// .setNegativeButton(R.string.cancel,
|
|
|
-// new DialogInterface.OnClickListener() {
|
|
|
-// @Override
|
|
|
-// public void onClick(DialogInterface dialog, int which) {
|
|
|
-// finish();
|
|
|
-// }
|
|
|
-// })
|
|
|
-// .setPositiveButton(R.string.setting,
|
|
|
-// new DialogInterface.OnClickListener() {
|
|
|
-// @Override
|
|
|
-// public void onClick(DialogInterface dialog, int which) {
|
|
|
-// Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
|
|
-// startActivityForResult(intent, REQUEST_CODE_OPEN_GPS);
|
|
|
-// }
|
|
|
-// })
|
|
|
-//
|
|
|
-// .setCancelable(false)
|
|
|
-// .show();
|
|
|
-// } else {
|
|
|
-// setScanRule();
|
|
|
-// startScan(bleName);
|
|
|
-// }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
private void uploadLogMessage(String message, String type) {
|
|
|
String da = "扫标机" + "------>>" + UserCache.getDeviceId() + "------>>" + message;
|
|
|
String s = BaseApplication.appendDataToLogFile(da, Constants.BLE_LOG_FILE_NAME);
|