feat
This commit is contained in:
parent
816ad0831d
commit
e49b5b2bf4
|
|
@ -1,5 +1,8 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext {
|
||||
kotlin_version = '1.9.22'
|
||||
}
|
||||
repositories {
|
||||
//添加阿里云镜像
|
||||
maven { url 'https://maven.aliyun.com/repository/public' }
|
||||
|
|
@ -13,6 +16,7 @@ buildscript {
|
|||
dependencies {
|
||||
// classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2'
|
||||
classpath 'com.android.tools.build:gradle:7.4.2'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
allprojects {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'org.jetbrains.kotlin.android'
|
||||
gradle.ext {
|
||||
pushVersion = '3.8.6'
|
||||
thirdPushVersion = '3.8.6'
|
||||
|
|
@ -64,6 +65,9 @@ android {
|
|||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
|
||||
}
|
||||
repositories {
|
||||
|
|
@ -100,6 +104,8 @@ dependencies {
|
|||
implementation 'com.google.android.material:material:1.0.0'
|
||||
// implementation 'com.github.bumptech.glide:glide:3.7.0'
|
||||
implementation 'com.github.bumptech.glide:glide:4.11.0'
|
||||
implementation 'androidx.core:core-ktx:1.10.1'
|
||||
// implementation 'androidx.activity:activity:1.8.0'
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
|
||||
|
||||
//Glide
|
||||
|
|
|
|||
|
|
@ -81,6 +81,16 @@
|
|||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 友盟 -->
|
||||
|
||||
|
||||
<!-- 蓝牙权限需求 -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <!-- 安卓12新增的蓝牙权限 -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <!-- 定位权限, 蓝牙搜索需要 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<!-- 使用相机 -->
|
||||
<!--
|
||||
<uses-feature
|
||||
|
|
@ -179,6 +189,11 @@
|
|||
android:theme="@style/MyAppTheme"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:replace="android:icon,android:theme,android:allowBackup">
|
||||
<activity
|
||||
android:name=".BluetoothActivity"
|
||||
android:exported="false"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/Transparent" />
|
||||
<activity
|
||||
android:name=".NewBindDeviceChoiceActivity"
|
||||
android:exported="false"
|
||||
|
|
|
|||
|
|
@ -7,22 +7,35 @@
|
|||
*/
|
||||
package com.ifish.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.AlertDialog;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.ifish.activity.newbind.NewBindDeviceActivity;
|
||||
import com.ifish.adapter.BlueToothController;
|
||||
import com.ifish.baseclass.BaseActivity;
|
||||
import com.ifish.permission.PermissionHelper;
|
||||
import com.ifish.utils.AnimationUtil;
|
||||
import com.ifish.utils.Commons;
|
||||
import com.ifish.utils.L;
|
||||
import com.ifish.utils.ToastUtil;
|
||||
import com.ifish.utils.WifiAdmin;
|
||||
import com.ifish.view.DisplayUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Jacky dada
|
||||
* @ClassName: BindTwoDeviceActivity
|
||||
|
|
@ -30,16 +43,29 @@ import com.ifish.view.DisplayUtil;
|
|||
* @date 2016-5-20 下午5:29:10
|
||||
*/
|
||||
public class BindTwoDeviceActivity extends BaseActivity {
|
||||
private ImageView iv_camera, iv_device, iv_more, iv_hot, iv_pet;
|
||||
private ImageView iv_camera, iv_device, iv_more, iv_hot, iv_pet,iv_bluetooth;
|
||||
private int width, height;
|
||||
private WifiAdmin wifiAdmin;
|
||||
private String wifissid = "";
|
||||
|
||||
private BlueToothController blueToothController = null;
|
||||
private String[] perlist = null;
|
||||
private PermissionHelper permissionHelper;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.bindtwodevice_activity);
|
||||
initTitle("选择设备");
|
||||
blueToothController = new BlueToothController();
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){
|
||||
perlist = new String[]{
|
||||
android.Manifest.permission.BLUETOOTH_SCAN,
|
||||
android.Manifest.permission.BLUETOOTH_ADVERTISE,
|
||||
android.Manifest.permission.BLUETOOTH_CONNECT,
|
||||
android.Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
android.Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
android.Manifest.permission.BLUETOOTH
|
||||
};
|
||||
}
|
||||
initView();//初始化控件
|
||||
}
|
||||
|
||||
|
|
@ -55,6 +81,7 @@ public class BindTwoDeviceActivity extends BaseActivity {
|
|||
iv_more = findMyViewById(R.id.iv_more);
|
||||
iv_hot = findMyViewById(R.id.iv_hot);
|
||||
iv_pet = findMyViewById(R.id.iv_pet);
|
||||
iv_bluetooth = findMyViewById(R.id.iv_bluetooth);
|
||||
//得到屏幕宽度按照比例为控件设置高度
|
||||
// double f=width/1.432;
|
||||
// height=(int)f;
|
||||
|
|
@ -72,6 +99,7 @@ public class BindTwoDeviceActivity extends BaseActivity {
|
|||
iv_device.setOnClickListener(this);
|
||||
iv_hot.setOnClickListener(this);
|
||||
iv_pet.setOnClickListener(this);
|
||||
iv_bluetooth.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -122,6 +150,7 @@ public class BindTwoDeviceActivity extends BaseActivity {
|
|||
wifissid = "";
|
||||
wifissid = wifiAdmin.getSSID();
|
||||
wifissid = wifiAdmin.updateSsid(wifissid);
|
||||
L.i("jjia----------------wifissid="+wifissid);
|
||||
if (TextUtils.isEmpty(wifissid)) {
|
||||
ToastUtil.show(getApplicationContext(), "您没有连接WiFi");
|
||||
return;
|
||||
|
|
@ -194,6 +223,86 @@ public class BindTwoDeviceActivity extends BaseActivity {
|
|||
finish();
|
||||
break;
|
||||
}
|
||||
|
||||
case R.id.iv_bluetooth:{
|
||||
permissionHelper = new PermissionHelper(BindTwoDeviceActivity.this, perlist, 10);
|
||||
if (permissionHelper.checkSelfPermission(perlist)){
|
||||
isOpen();
|
||||
}else {
|
||||
permissionHelper.request(new PermissionHelper.PermissionCallback() {
|
||||
@Override
|
||||
public void onPermissionGranted() {
|
||||
isOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIndividualPermissionGranted(String[] grantedPermission) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionDenied() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionDeniedBySystem() {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getPer(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void toBlueTooth(){
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(BindTwoDeviceActivity.this, BluetoothActivity.class);
|
||||
intent.putExtra("devicetype", "bluetooth");
|
||||
intent.putExtra("title", "蓝牙插座");
|
||||
startActivity(intent);
|
||||
AnimationUtil.startAnimation(BindTwoDeviceActivity.this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode==10){
|
||||
isOpen();
|
||||
}else if (requestCode == 11){ //打开蓝牙
|
||||
toBlueTooth();
|
||||
}
|
||||
}
|
||||
|
||||
private void openBlueTooth(){
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(BindTwoDeviceActivity.this, AlertDialog.THEME_HOLO_LIGHT);
|
||||
dialog.setCancelable(true);
|
||||
dialog.setMessage("请打开手机蓝牙");
|
||||
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
arg0.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.setPositiveButton("打开", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
blueToothController.open(BindTwoDeviceActivity.this);
|
||||
AnimationUtil.finishAnimation(BindTwoDeviceActivity.this);
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void isOpen(){
|
||||
if (blueToothController.isOpen()){
|
||||
toBlueTooth();
|
||||
}else {
|
||||
openBlueTooth();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,107 @@
|
|||
package com.ifish.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.ParcelUuid;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
import com.ifish.adapter.BlueToothController;
|
||||
import com.ifish.baseclass.BaseActivity;
|
||||
import com.ifish.utils.BlueToothUtil;
|
||||
import com.ifish.utils.L;
|
||||
import com.ifish.utils.ToastUtil;
|
||||
|
||||
|
||||
public class BluetoothActivity extends BaseActivity {
|
||||
|
||||
BlueToothController blueToothController = new BlueToothController();
|
||||
|
||||
IntentFilter foundFilter = null;
|
||||
TextView name ;
|
||||
Button tv_pair;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_bluetooth);
|
||||
|
||||
name = findMyViewById(R.id.tv_name);
|
||||
tv_pair = findMyViewById(R.id.tv_pair);
|
||||
initTitle("蓝牙选择设备");
|
||||
foundFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);//获得扫描结果
|
||||
foundFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);//绑定状态变化
|
||||
foundFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);//开始扫描
|
||||
foundFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);//扫描结束
|
||||
|
||||
registerReceiver(broadcastReceiver,foundFilter);
|
||||
blueToothController.find();
|
||||
|
||||
tv_pair.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (bluetoothDevice!=null){
|
||||
BlueToothUtil.Companion.boundDevice(bluetoothDevice);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
BluetoothDevice bluetoothDevice = null;
|
||||
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
|
||||
@SuppressLint("MissingPermission")
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (BluetoothDevice.ACTION_FOUND .equals(intent.getAction())){
|
||||
BluetoothDevice device = null;
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
|
||||
device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE,BluetoothDevice.class);
|
||||
}else {
|
||||
device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
}
|
||||
if (device!=null && device.getBondState() ==10){
|
||||
String deviceName= device.getName();
|
||||
if (!TextUtils.isEmpty(deviceName) &&
|
||||
(
|
||||
// deviceName.contains("ifishly") ||
|
||||
deviceName.equals("ifishly-fee0")
|
||||
// deviceName.contains("LE-Bose")
|
||||
|
||||
)
|
||||
){
|
||||
bluetoothDevice = device;
|
||||
name.setText(deviceName);
|
||||
|
||||
ParcelUuid[] sss = device.getUuids();
|
||||
if (sss!=null && sss.length>0){
|
||||
for (ParcelUuid x:sss){
|
||||
if (x!=null){
|
||||
L.i(device.getName()+"蓝牙设备名称--Uuid--"+x.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
}else {
|
||||
L.i("蓝牙设备名称--null0-");
|
||||
}
|
||||
L.i("蓝牙设备名称-1-"+device.toString());
|
||||
}
|
||||
L.i("蓝牙设备名称--"+device.getName());
|
||||
}
|
||||
}else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(intent.getAction())){
|
||||
ToastUtil.show(BluetoothActivity.this,"蓝牙搜索结束");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -143,77 +143,7 @@ public class AirKissUtil {
|
|||
// });
|
||||
// udpReceiver.start();
|
||||
|
||||
// 发送AirKiss
|
||||
sendSubscribe = Observable.create(new Observable.OnSubscribe<String>() {
|
||||
@Override
|
||||
public void call(Subscriber<? super String> subscriber) {
|
||||
subscriber.onNext("start");
|
||||
byte[] DUMMY_DATA = new byte[1500];
|
||||
DatagramSocket sendSocket = null;
|
||||
try {
|
||||
sendSocket = new DatagramSocket();
|
||||
sendSocket.setBroadcast(true);
|
||||
int[] encoded_data = airKissEncoder.getEncodedData();
|
||||
for (int encoded_datum : encoded_data) {
|
||||
DatagramPacket pkg = new DatagramPacket(DUMMY_DATA,
|
||||
encoded_datum,
|
||||
InetAddress.getByName("255.255.255.255"),
|
||||
10000);
|
||||
sendSocket.send(pkg);
|
||||
Thread.sleep(4);
|
||||
}
|
||||
|
||||
subscriber.onCompleted();
|
||||
} catch (Exception e) {
|
||||
subscriber.onError(e);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
sendSocket.close();
|
||||
sendSocket.disconnect();
|
||||
}
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<String>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
// ToastUtil.show(activity, "连接信号发送完成");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
LogUtils.d("LHD onError e "+e.getLocalizedMessage());
|
||||
ToastUtil.show(activity, "连接失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(String string) {
|
||||
LogUtils.d("LHD send onNext =" + string);
|
||||
if (mDialog != null) {
|
||||
mDialog.dismiss();
|
||||
mDialog.setTitle("配网中");
|
||||
mDialog.setMessage("发送配网信息...");
|
||||
mDialog.setCancelable(false);
|
||||
mDialog.show();
|
||||
}
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//发送配网ssid pwd,因为字节发送需要时间比较久,此处只是设置比较短的提示,但实际上后台线程还在发送中。
|
||||
if (mDialog != null) {
|
||||
mDialog.dismiss();
|
||||
mDialog.setTitle("连接设备");
|
||||
mDialog.setMessage("正在接受设备信息,请耐心等待...");
|
||||
mDialog.setCancelable(false);
|
||||
mDialog.show();
|
||||
}
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
//接收udp包
|
||||
receiveSubscribe = Observable.create(new Observable.OnSubscribe<String>() {
|
||||
|
|
@ -251,6 +181,82 @@ public class AirKissUtil {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 发送AirKiss
|
||||
sendSubscribe = Observable.create(new Observable.OnSubscribe<String>() {
|
||||
@Override
|
||||
public void call(Subscriber<? super String> subscriber) {
|
||||
subscriber.onNext("start");
|
||||
L.i("jjia----------------start=");
|
||||
byte[] DUMMY_DATA = new byte[1500];
|
||||
DatagramSocket sendSocket = null;
|
||||
try {
|
||||
sendSocket = new DatagramSocket();
|
||||
sendSocket.setBroadcast(true);
|
||||
int[] encoded_data = airKissEncoder.getEncodedData();
|
||||
for (int encoded_datum : encoded_data) {
|
||||
DatagramPacket pkg = new DatagramPacket(DUMMY_DATA,
|
||||
encoded_datum,
|
||||
InetAddress.getByName("255.255.255.255"),
|
||||
10000);
|
||||
sendSocket.send(pkg);
|
||||
Thread.sleep(4);
|
||||
}
|
||||
|
||||
subscriber.onCompleted();
|
||||
} catch (Exception e) {
|
||||
subscriber.onError(e);
|
||||
e.printStackTrace();
|
||||
L.i("jjia----------------catch=");
|
||||
} finally {
|
||||
sendSocket.close();
|
||||
sendSocket.disconnect();
|
||||
}
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<String>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
// ToastUtil.show(activity, "连接信号发送完成");
|
||||
L.i("jjia----------------onCompleted=");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
LogUtils.d("LHD onError e "+e.getLocalizedMessage());
|
||||
L.i("jjia----------------onError="+e.getLocalizedMessage());
|
||||
ToastUtil.show(activity, "连接失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(String string) {
|
||||
LogUtils.d("LHD send onNext =" + string);
|
||||
if (mDialog != null) {
|
||||
mDialog.dismiss();
|
||||
mDialog.setTitle("配网中");
|
||||
mDialog.setMessage("发送配网信息...");
|
||||
mDialog.setCancelable(false);
|
||||
mDialog.show();
|
||||
}
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//发送配网ssid pwd,因为字节发送需要时间比较久,此处只是设置比较短的提示,但实际上后台线程还在发送中。
|
||||
if (mDialog != null) {
|
||||
mDialog.dismiss();
|
||||
mDialog.setTitle("连接设备");
|
||||
mDialog.setMessage("正在接受设备信息,请耐心等待...");
|
||||
mDialog.setCancelable(false);
|
||||
mDialog.show();
|
||||
}
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void receivePackage(AirKissEncoder airKissEncoder, Subscriber subscriber) {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import com.ifish.utils.ClickUtil;
|
|||
import com.ifish.utils.Commons;
|
||||
import com.ifish.utils.HttpManager;
|
||||
import com.ifish.utils.KVUtil;
|
||||
import com.ifish.utils.L;
|
||||
import com.ifish.utils.SPUtil;
|
||||
import com.ifish.utils.ToastUtil;
|
||||
import com.ifish.utils.WifiAdmin;
|
||||
|
|
@ -85,6 +86,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
|
|||
checkWifiUtil = new CheckWifiUtil();
|
||||
airKissUtil = new AirKissUtil();
|
||||
devicetype = getIntent().getStringExtra("devicetype");
|
||||
L.i("jjia----------------devicetype="+devicetype);
|
||||
airKissUtil.init(this,devicetype);
|
||||
//默认AP联网
|
||||
curConnectType = ConnectType.AirKiss;
|
||||
|
|
@ -107,6 +109,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
|
|||
}
|
||||
tvWifiName.setText(wifiname);
|
||||
bssid = wifiAdmin.getBSSID();
|
||||
L.i("jjia----------------bssid="+bssid);
|
||||
if (!TextUtils.isEmpty(wifiname)) {
|
||||
// String pwd = KVUtil.getString(wifiname, "");
|
||||
String pwd = sp.getString(wifiname, "");
|
||||
|
|
@ -274,18 +277,22 @@ public class NewBindDeviceActivity extends AppCompatActivity {
|
|||
//根据选择的联网类型跳转不同的逻辑
|
||||
String ssid = tvWifiName.getText().toString();
|
||||
String pwd = tvWifiPwd.getText().toString();
|
||||
|
||||
//一系列判断逻辑
|
||||
boolean canConnect = checkWifiUtil.checkWifiCanUse(this, ssid, pwd);
|
||||
L.i("jjia----------------canConnect="+canConnect);
|
||||
sp.putString(ssid,pwd);
|
||||
if (!canConnect) {
|
||||
return;
|
||||
}
|
||||
L.i("jjia----------------curConnectType="+curConnectType);
|
||||
switch (curConnectType) {
|
||||
case SmartConfig:
|
||||
// 处理SmartConfig逻辑
|
||||
Intent intent = new Intent();
|
||||
String devicetype = getIntent().getStringExtra("devicetype");
|
||||
String devicetdevicetypeype = getIntent().getStringExtra("devicetype");
|
||||
LogUtils.d("LHD 快捷联网 smartConfig devicetype = "+devicetype);
|
||||
|
||||
if ("camera".equals(devicetype)) {
|
||||
intent.setClass(NewBindDeviceActivity.this, BindCameraActivity.class);
|
||||
} else if ("pet".equals(devicetype)) {
|
||||
|
|
@ -310,6 +317,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
|
|||
break;
|
||||
case AirKiss:
|
||||
// 处理AirKiss逻辑
|
||||
L.i("jjia----------------bssid="+bssid);
|
||||
ToastUtil.show(NewBindDeviceActivity.this, "开始AirKiss联网...");
|
||||
airKissUtil.connectDeviceByAirKiss(this, ssid, bssid, pwd);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
package com.ifish.adapter;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import com.ifish.utils.ToastUtil;
|
||||
|
||||
public class BlueToothController {
|
||||
|
||||
BluetoothAdapter adapter;
|
||||
|
||||
public BlueToothController() {
|
||||
adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
if (adapter != null) {
|
||||
return adapter.isEnabled();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void open(Activity activity) {
|
||||
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
||||
|
||||
ToastUtil.show(activity,"请");
|
||||
return;
|
||||
}
|
||||
activity.startActivityForResult(intent, 11);
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public boolean find(){
|
||||
if (adapter!=null){
|
||||
return adapter.startDiscovery();
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.ifish.utils
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.bluetooth.BluetoothDevice
|
||||
import java.util.UUID
|
||||
|
||||
class BlueToothUtil {
|
||||
|
||||
companion object{
|
||||
@SuppressLint("MissingPermission")
|
||||
fun boundDevice(devicex: BluetoothDevice?){
|
||||
var method = BluetoothDevice::class.java.getMethod("createBond")
|
||||
method.invoke(devicex)
|
||||
var clientSocket = devicex!!.createRfcommSocketToServiceRecord(UUID.fromString(devicex.address))
|
||||
clientSocket.connect()
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun boundDevice2(devicex: BluetoothDevice?){
|
||||
devicex
|
||||
var method = BluetoothDevice::class.java.getMethod("createBond")
|
||||
method.invoke(devicex)
|
||||
var clientSocket = devicex!!.createRfcommSocketToServiceRecord(UUID.randomUUID())
|
||||
clientSocket.connect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/color_F2F2F2"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
android:id="@+id/in_daohang"
|
||||
layout="@layout/title_layout" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/tv_pair"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="蓝牙配对连接"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -24,6 +24,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:src="@drawable/bindtwo_camera"
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
<ImageView
|
||||
|
|
@ -31,6 +32,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:src="@drawable/bindtwo_device"
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
<ImageView
|
||||
|
|
@ -38,6 +40,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:src="@drawable/bindtwo_hot"
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
<ImageView
|
||||
|
|
@ -45,13 +48,22 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:src="@drawable/device_petdevice"
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_bluetooth"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:src="@drawable/device_petdevice"
|
||||
android:scaleType="fitXY" />
|
||||
<ImageView
|
||||
android:id="@+id/iv_more"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:src="@drawable/bindtwo_more"
|
||||
android:scaleType="fitXY" />
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue