路由器名称长度控制
This commit is contained in:
parent
5eaef0d8a4
commit
59625c2e9f
|
|
@ -89,7 +89,7 @@ public class HotSpotConnentDeviceActivity extends BaseActivity {
|
|||
while (isNext < 10) {
|
||||
isNext++;
|
||||
Thread.sleep(1000);
|
||||
OrderDeviceConnectModel model = OrderModel.OrderDeviceConnectModel(ssidname, ssidpwd);//设置正式环境域名
|
||||
OrderDeviceConnectModel model = OrderModel.OrderDeviceConnectModel(ssidname, ssidpwd,false);//设置正式环境域名
|
||||
byte[] bys = ModelCodec.enCode(model);//解析数据
|
||||
InetAddress address = InetAddress.getByName("192.168.4.1");
|
||||
DatagramPacket dp = new DatagramPacket(bys, bys.length, address, 333);
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class HotSpotConnentPetDeviceActivity extends BaseActivity {
|
|||
while (isNext < 10) {
|
||||
isNext++;
|
||||
Thread.sleep(1000);
|
||||
OrderDeviceConnectModel model = OrderModel.OrderDeviceConnectModel(ssidname, ssidpwd);//设置正式环境域名
|
||||
OrderDeviceConnectModel model = OrderModel.OrderDeviceConnectModel(ssidname, ssidpwd,false);//设置正式环境域名
|
||||
byte[] bys = ModelCodec.enCode(model);//解析数据
|
||||
InetAddress address = InetAddress.getByName("192.168.4.1");
|
||||
DatagramPacket dp = new DatagramPacket(bys, bys.length, address, 333);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import com.ifish.activity.HotSpotConnentPetDeviceActivity;
|
|||
import com.ifish.activity.R;
|
||||
import com.ifish.utils.AnimationUtil;
|
||||
import com.ifish.utils.KVUtil;
|
||||
import com.ifish.utils.L;
|
||||
import com.ifish.utils.SPUtil;
|
||||
import com.ifish.utils.ToastUtil;
|
||||
import com.ifish.utils.WifiUtil;
|
||||
|
|
@ -67,7 +68,7 @@ public class CheckWifiUtil {
|
|||
* @param wifipwd
|
||||
* @return
|
||||
*/
|
||||
public boolean checkWifiCanUse(AppCompatActivity activity, String wifiname, String wifipwd) {
|
||||
public boolean checkWifiCanUse(AppCompatActivity activity, String wifiname, String wifipwd,boolean isBlue) {
|
||||
if (!checkWifiCanUse(activity)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -82,6 +83,59 @@ public class CheckWifiUtil {
|
|||
return false;
|
||||
}
|
||||
|
||||
int ssidLen = wifiname.length();
|
||||
int pwdLen = wifipwd.length();
|
||||
int ssidLength = wifiname.getBytes().length;
|
||||
int pwdLength = wifipwd.getBytes().length;
|
||||
|
||||
|
||||
L.i("jjia-----1---"+ssidLen);
|
||||
L.i("jjia-----2---"+ssidLength);
|
||||
if (isBlue){ // 蓝牙
|
||||
if (ssidLength > 45){
|
||||
if (ssidLength == ssidLen){
|
||||
ToastUtil.show(activity.getApplicationContext(), "路由器名称长度不能超过45个字符");
|
||||
return false;
|
||||
}else {
|
||||
ToastUtil.show(activity.getApplicationContext(), "路由器名称长度不能超过15个汉字");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (ssidLength > 20){
|
||||
if (ssidLength == ssidLen){
|
||||
ToastUtil.show(activity.getApplicationContext(), "路由器名称长度不能超过20个字符");
|
||||
return false;
|
||||
}else {
|
||||
ToastUtil.show(activity.getApplicationContext(), "路由器名称长度不能超过6个汉字");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlue){ // 蓝牙
|
||||
if (pwdLength > 30){
|
||||
if (pwdLength == pwdLen){
|
||||
ToastUtil.show(activity.getApplicationContext(), "路由器密码长度不能超过30个字符");
|
||||
return false;
|
||||
}else {
|
||||
ToastUtil.show(activity.getApplicationContext(), "路由器密码长度不能超过6个汉字");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (pwdLength > 20){
|
||||
if (pwdLength == pwdLen){
|
||||
ToastUtil.show(activity.getApplicationContext(), "路由器密码长度不能超过20个字符");
|
||||
return false;
|
||||
}else {
|
||||
ToastUtil.show(activity.getApplicationContext(), "路由器密码长度不能超过6个汉字");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WifiManager wifiManager = (WifiManager) activity.getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
ToastUtil.show(activity.getApplicationContext(), "缺少联网权限");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.ifish.activity.newbind;
|
||||
|
||||
import static com.ifish.activity.newbind.ConnectType.BlueTooth;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
|
|
@ -149,7 +151,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
|
|||
|
||||
BleManager.getInstance().disconnectAllDevice();
|
||||
if ("bluetooth".equals(type)){
|
||||
curConnectType = ConnectType.BlueTooth;
|
||||
curConnectType = BlueTooth;
|
||||
}else {
|
||||
//默认AP联网
|
||||
curConnectType = ConnectType.AirKiss;
|
||||
|
|
@ -255,7 +257,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void bleConnect() {
|
||||
curConnectType = ConnectType.BlueTooth;
|
||||
curConnectType = BlueTooth;
|
||||
switchUIConnectType(curConnectType);
|
||||
}
|
||||
});
|
||||
|
|
@ -389,7 +391,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
|
|||
String pwd = tvWifiPwd.getText().toString().trim();
|
||||
|
||||
//一系列判断逻辑
|
||||
boolean canConnect = checkWifiUtil.checkWifiCanUse(this, ssid, pwd);
|
||||
boolean canConnect = checkWifiUtil.checkWifiCanUse(this, ssid, pwd,curConnectType==BlueTooth);
|
||||
L.i("jjia----------------canConnect="+canConnect);
|
||||
sp.putString(ssid,pwd);
|
||||
if (!canConnect) {
|
||||
|
|
@ -641,7 +643,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
|
|||
String ssid = tvWifiName.getText().toString();
|
||||
String pwd = tvWifiPwd.getText().toString();
|
||||
|
||||
OrderDeviceConnectModel model = OrderModel.OrderDeviceConnectModel(ssid, pwd);//设置正式环境域名
|
||||
OrderDeviceConnectModel model = OrderModel.OrderDeviceConnectModel(ssid, pwd,true);//设置正式环境域名
|
||||
byte[] data = ModelCodec.enCode(model);
|
||||
BleManager.getInstance().write(currentDevice, SERVICE_UUID, WRITE_UUID, data,false, new BleWriteCallback() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -15,10 +15,15 @@ import java.io.Serializable;
|
|||
* @Description: 设备设置tcp域名命令39字节(17字节+22字节)
|
||||
*/
|
||||
public class OrderDeviceConnectModel extends HeadModel implements Serializable {
|
||||
private boolean isNew = false;
|
||||
|
||||
public OrderDeviceConnectModel(boolean x){
|
||||
this.isNew = x;
|
||||
}
|
||||
//路由器wifi名
|
||||
private byte[] ssid_name = new byte[Commons.SSID_LENGTH];
|
||||
private byte[] ssid_name = new byte[ isNew ?Commons.SSID_LENGTH:20];
|
||||
//路由器wifi密码
|
||||
private byte[] ssid_password = new byte[Commons.SSID_LENGTH];
|
||||
private byte[] ssid_password = new byte[isNew?Commons.SSID_LENGTH:20];
|
||||
|
||||
public byte[] getSsid_name() {
|
||||
return ssid_name;
|
||||
|
|
|
|||
|
|
@ -70,13 +70,13 @@ public class OrderModel {
|
|||
/**
|
||||
* 链接路由器指令
|
||||
*/
|
||||
public final static OrderDeviceConnectModel OrderDeviceConnectModel(String ssid_name, String ssid_pwd) {
|
||||
OrderDeviceConnectModel model = new OrderDeviceConnectModel();
|
||||
public final static OrderDeviceConnectModel OrderDeviceConnectModel(String ssid_name, String ssid_pwd,boolean x) {
|
||||
OrderDeviceConnectModel model = new OrderDeviceConnectModel(x);
|
||||
//15字节数据包头
|
||||
model.setType((byte) 0);
|
||||
model.setCheck_code((byte) 18);
|
||||
// model.setRemote_len((byte) 57);
|
||||
model.setRemote_len((byte) Commons.Remote_len);
|
||||
model.setRemote_len((byte) (x?Commons.Remote_len:57));
|
||||
//wifi账号密码
|
||||
byte[] wifi_Account = model.getSsid_name();
|
||||
byte[] wifi_Password = model.getSsid_password();
|
||||
|
|
|
|||
Loading…
Reference in New Issue