扫描蓝牙二维码,准备配网
This commit is contained in:
@@ -4,6 +4,7 @@ import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -27,11 +28,15 @@ import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.permission.PermissionActivity;
|
||||
import com.ckkj.water.plan.entity.WaterPlanWeekEntity;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.maning.mlkitscanner.scan.MNScanManager;
|
||||
import com.maning.mlkitscanner.scan.callback.act.MNScanCallback;
|
||||
import com.scwang.smart.refresh.footer.ClassicsFooter;
|
||||
import com.scwang.smart.refresh.layout.api.RefreshHeader;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -135,9 +140,41 @@ 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){
|
||||
ToastUtil.showShort(mContext,results.get(0).toString());
|
||||
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"))){
|
||||
ToastUtil.showShort(mContext,"请扫描正确的二维码");
|
||||
return;
|
||||
}
|
||||
entity.setMacAddress(json.getString("mac"));
|
||||
entity.setDeviceName(json.getString("name"));
|
||||
if(entity != null){
|
||||
//这里拿到Mac地址,需要去服务器查询当前Mac的绑定状态
|
||||
mPresenter.bindDeviceStatus(entity);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
break;
|
||||
case MNScanManager.RESULT_FAIL:
|
||||
@@ -198,6 +235,21 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前设备绑定状态
|
||||
* @param entity
|
||||
*/
|
||||
@Override
|
||||
public void queryDeviceBindStatusSuccess(WaterDeviceEntity entity) {
|
||||
switch (entity.getBindDeviceStatus()){
|
||||
case 302:
|
||||
//Todo 即这是一台没有在mqtt中注册的设备,App 需要通过蓝牙连接,并实现配网
|
||||
//Todo entity 中有Mac地址,和设备名称,根据代码中现有的扫描、连接、配网代码,实现功能
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
|
||||
Reference in New Issue
Block a user