扫描二维码,连接配网1

This commit is contained in:
fengjignqi
2026-06-14 09:06:26 +08:00
parent 4d4df82c6e
commit dab61da6c5
11 changed files with 67 additions and 28 deletions

View File

@@ -158,27 +158,27 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
public void onActivityResult(int resultCode, Intent data) {
switch (resultCode) {
case MNScanManager.RESULT_SUCCESS:
ArrayList<String> results = data.getStringArrayListExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS);
if (results == null || results.isEmpty()) {
ToastUtil.showShort(mContext, "二维码内容不能为空");
return;
}
String scanContent = results.get(0);
if (TextUtils.isEmpty(scanContent)) {
ToastUtil.showShort(mContext, "二维码内容不能为空");
return;
}
JSONObject json;
try {
json = new JSONObject(scanContent);
} catch (JSONException e) {
ToastUtil.showShort(mContext, "二维码格式错误");
return;
}
try {
ArrayList<String> results = data.getStringArrayListExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS);
if (results == null || results.isEmpty()) {
ToastUtil.showShort(mContext, "二维码内容不能为空");
return;
}
String scanContent = results.get(0);
if (TextUtils.isEmpty(scanContent)) {
ToastUtil.showShort(mContext, "二维码内容不能为空");
return;
}
JSONObject json;
try {
json = new JSONObject(scanContent);
} catch (JSONException e) {
ToastUtil.showShort(mContext, "二维码格式错误");
return;
}
WaterDeviceEntity entity = new WaterDeviceEntity();
if(TextUtils.isEmpty(json.getString("mac"))
|| TextUtils.isEmpty(json.getString("name"))){
@@ -192,7 +192,8 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
mPresenter.bindDeviceStatus(entity);
}
} catch (JSONException e) {
throw new RuntimeException(e);
ToastUtil.showShort(mContext, "二维码格式错误");
return;
}
break;
case MNScanManager.RESULT_FAIL: