diff --git a/app/build.gradle b/app/build.gradle
index d861378..d73fd95 100755
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -116,6 +116,8 @@ dependencies {
//深信服零信任SDK
implementation files('libs/SangforSDK.aar')
+ //W3蓝牙传感器SDK
+ implementation files('libs/blemanager.aar')
implementation libs.circleimageview
//腾讯APP崩溃分析
implementation libs.crashreport
diff --git a/app/libs/blemanager.aar b/app/libs/blemanager.aar
new file mode 100644
index 0000000..2464e93
Binary files /dev/null and b/app/libs/blemanager.aar differ
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index cc1c6fe..d587049 100755
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -7,11 +7,12 @@
android:name="android.hardware.bluetooth_le"
android:required="true" />
-
+
-
+
diff --git a/app/src/main/java/com/rehome/dywoa/Contans.java b/app/src/main/java/com/rehome/dywoa/Contans.java
index 8c7ed44..038f0be 100755
--- a/app/src/main/java/com/rehome/dywoa/Contans.java
+++ b/app/src/main/java/com/rehome/dywoa/Contans.java
@@ -272,6 +272,7 @@ public class Contans {
public final static String LOGIN_TOKEN = "LOGIN_TOKEN";
public final static String NFCBM = "NFCBM";
+ public final static String KEY_BLUE_TOOTH = "KEY_BLUE_TOOTH";
public final static String USERNAME = "USERNAME";
public final static String SCID = "scid";
diff --git a/app/src/main/java/com/rehome/dywoa/bleUtil/BlueToothDeviceActivity.java b/app/src/main/java/com/rehome/dywoa/bleUtil/BlueToothDeviceActivity.java
index edc656e..458e606 100644
--- a/app/src/main/java/com/rehome/dywoa/bleUtil/BlueToothDeviceActivity.java
+++ b/app/src/main/java/com/rehome/dywoa/bleUtil/BlueToothDeviceActivity.java
@@ -1,19 +1,27 @@
package com.rehome.dywoa.bleUtil;
import android.Manifest;
+import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
+import android.graphics.Color;
import android.os.Build;
-import android.os.Bundle;
+import com.bjzc.blemanager.BluetoothLeService;
import android.os.Handler;
import android.util.Log;
+import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
import android.widget.ListView;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
@@ -23,14 +31,20 @@ import androidx.core.app.ActivityCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
-import com.clj.fastble.BleManager;
+//import com.clj.fastble.BleManager;
+import com.bjzc.blemanager.BleManager;
import com.clj.fastble.callback.BleScanCallback;
import com.clj.fastble.data.BleDevice;
+import com.clj.fastble.data.BleScanState;
import com.clj.fastble.scan.BleScanRuleConfig;
import com.google.gson.Gson;
+import com.rehome.dywoa.Contans;
import com.rehome.dywoa.R;
+import com.rehome.dywoa.adapter.XzjhAdapter;
import com.rehome.dywoa.base.BaseActivity;
+import com.rehome.dywoa.utils.SPUtils;
import java.util.ArrayList;
import java.util.List;
@@ -42,6 +56,7 @@ import java.util.List;
public class BlueToothDeviceActivity extends BaseActivity {
ListView lv;
+ TextView tx_data;
private BluetoothAdapter mBluetoothAdapter;
private ArrayList mPermissionList = new ArrayList();
private BluetoothLeScanner bluetoothLeScanner;
@@ -54,6 +69,10 @@ public class BlueToothDeviceActivity extends BaseActivity {
//private LeDeviceListAdapter leDeviceListAdapter = new LeDeviceListAdapter();
private LeDeviceListAdapter mLeDeviceListAdapter;
+ private BleManager ble;
+ private int selectItem = -1;
+ private String cmd = "";
+
@Override
public int getContentViewID() {
return R.layout.activity_blue_tooth_device;
@@ -61,6 +80,84 @@ public class BlueToothDeviceActivity extends BaseActivity {
@Override
public void initView() {
+ lv = findViewById(R.id.lv);
+ tx_data = findViewById(R.id.tx_data);
+ ble= BleManager.getInstance();
+ String str=ble.init(BlueToothDeviceActivity.this);
+ showLog(str);
+
+ if("BLE is not supported".equals(str)){
+ showToast("当前设备不支持低功耗蓝牙,无法连接传感器采集数据");
+ }
+ if("Bluetooth not supported".equals(str)){
+ showToast("当前设备不支持蓝牙功能");
+ }
+ if("Bluetooth not enabled".equals(str)){
+ showToast("蓝牙功能没有开启");
+ }
+ if("ACCESS_COARSE_LOCATION permission denied".equals(str)){
+ showToast("您未授权开启蓝牙扫描附近的设备,请先开启蓝牙权限");
+ }
+ if("context is no Activity".equals(str)){
+ showToast("Init(context)方法的参数必须是 Activity");
+ }
+
+ ble.setOnReceiveListener(new BleManager.OnReceiveListener() {
+ @SuppressLint("SetTextI18n")
+ @Override
+ public void onShowMessage(Context context, Intent intent) {
+ final String action = intent.getAction();
+ if (BluetoothDevice.ACTION_FOUND.equals(action)) {
+ BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ if (ActivityCompat.checkSelfPermission(BlueToothDeviceActivity.this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
+ // TODO: Consider calling
+ // ActivityCompat#requestPermissions
+ // here to request the missing permissions, and then overriding
+ // public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ // int[] grantResults)
+ // to handle the case where the user grants the permission. See the documentation
+ // for ActivityCompat#requestPermissions for more details.
+ return;
+ }
+ showLog("扫描发现设备" + device.getName() + "," + device.getAddress());
+ String deviceName = device.getName();
+ if (deviceName != null && !deviceName.isEmpty()){
+ //showLog(new Gson().toJson(device));
+ mLeDeviceListAdapter.addDevice(device);
+ mLeDeviceListAdapter.notifyDataSetChanged();
+ }
+ } else if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
+ showLog("连接");
+ mLeDeviceListAdapter.setSelectItem(selectItem);
+ mLeDeviceListAdapter.notifyDataSetChanged();
+
+ BluetoothDevice device = mLeDeviceListAdapter.getDevice(selectItem);
+ String deviceName = device.getName();
+ if (deviceName != null && !deviceName.isEmpty()){
+ SPUtils.put(context, Contans.KEY_BLUE_TOOTH,device.getAddress());
+ }
+ } else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
+ showLog("断开");
+ } else if (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
+ showLog("数据传输通道准备就绪,可以发送数据了。");
+ } else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
+ byte[] data= intent.getByteArrayExtra(BluetoothLeService.EXTRA_DATA);
+ String resultReceive = new String(data);
+ showLog("收到传感器数据" + resultReceive);
+ if("VR".equals(cmd)){
+ showLog(resultReceive);
+ }else{
+ tx_data.setText("接收数值:"+resultReceive);
+ }
+ if("0F3101".equals(cmd)){
+ ble.write("VR", false);
+ cmd="VR";
+ }
+
+ }
+ }
+ });
+
initToolbar("蓝牙数据管理", "扫描并确认", new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -68,14 +165,69 @@ public class BlueToothDeviceActivity extends BaseActivity {
mLeDeviceListAdapter.clear();
mLeDeviceListAdapter.notifyDataSetChanged();
//initBlueTooth();
- if(BleManager.getInstance().isSupportBle()){
- initBlueToothFastBle();
+// if(BleManager.getInstance().isSupportBle()){
+// initBlueToothFastBle();
+// }else{
+// showToast("当前设备不支持低功耗蓝牙,无法连接传感器采集数据");
+// }
+ if("OK".equals(str)){
+ ble.scan();
}
}
});
- BleManager.getInstance().init(getApplication());
- lv = findViewById(R.id.lv);
- mLeDeviceListAdapter = new LeDeviceListAdapter(BlueToothDeviceActivity.this);
+ //BleManager.getInstance().init(getApplication());
+
+
+
+
+ mLeDeviceListAdapter = new LeDeviceListAdapter(new LeDeviceListAdapter.CallBackBlueToothBind() {
+
+ @Override
+ public void Click(int position) {
+ showLog(String.valueOf(position));
+ BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
+ if (ActivityCompat.checkSelfPermission(BlueToothDeviceActivity.this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
+ // TODO: Consider calling
+ // ActivityCompat#requestPermissions
+ // here to request the missing permissions, and then overriding
+ // public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ // int[] grantResults)
+ // to handle the case where the user grants the permission. See the documentation
+ // for ActivityCompat#requestPermissions for more details.
+ return;
+ }
+ selectItem=position;
+ ble.connect(device.getAddress(),device.getName());
+ }
+ }, new LeDeviceListAdapter.CallBackBlueToothUnBind() {
+ @Override
+ public void Click(int position) {
+
+ }
+ }, new LeDeviceListAdapter.CallBackBlueToothSendData() {
+ @Override
+ public void Click(int position) {
+ //ble.write(String cmd, Boolean ishex)
+ //读固件版本号
+ //ble.write("VR", false);
+ //读电量
+ //ble.write("BV", false);
+ //温度测量
+ ble.write("0B0B6300", true);
+ //距离测量
+ //ble.write("4453", true);
+ //转速测量
+ //ble.write("0F3101", true);
+ //cmd="0F3101";
+ //加速度测量
+ //ble.write("1F11", true);
+ //速度测量。
+ //ble.write("1F12", true);
+ //位移测量
+ //ble.write("1F13", true);
+
+ }
+ });
lv.setAdapter(mLeDeviceListAdapter);
}
@@ -84,6 +236,19 @@ public class BlueToothDeviceActivity extends BaseActivity {
}
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ ble.scan();
+ ble.disconnect();
+// if(BleManager.getInstance().getScanSate()== BleScanState.STATE_SCANNING){
+// BleManager.getInstance().cancelScan();
+// }
+// BleManager.getInstance().disconnectAllDevice();
+// BleManager.getInstance().destroy();
+ }
+
+
private void initPermission(){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){
// Android 版本大于等于 Android12 时
@@ -135,12 +300,12 @@ public class BlueToothDeviceActivity extends BaseActivity {
public void initBlueTooth() {
- boolean bluetoothAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
- if(bluetoothAvailable){
- showLog("传统蓝牙可用");
- }else{
- showLog("传统蓝牙不可用");
- }
+// boolean bluetoothAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
+// if(bluetoothAvailable){
+// showLog("传统蓝牙可用");
+// }else{
+// showLog("传统蓝牙不可用");
+// }
boolean bluetoothLEAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE);
if(bluetoothLEAvailable){
@@ -152,41 +317,65 @@ public class BlueToothDeviceActivity extends BaseActivity {
}
}
- public void initBlueToothFastBle() {
- BleManager.getInstance()
- .enableLog(true)
- .setReConnectCount(1, 5000)
- .setSplitWriteNum(20)
- .setConnectOverTime(10000)
- .setOperateTimeout(5000);
+// public void initBlueToothFastBle() {
+// if(BleManager.getInstance().getScanSate()== BleScanState.STATE_SCANNING){
+// BleManager.getInstance().cancelScan();
+// }
+// BleManager.getInstance()
+// .enableLog(true)
+// .setReConnectCount(1, 5000)
+// .setSplitWriteNum(20)
+// .setConnectOverTime(10000)
+// .setOperateTimeout(5000);
//
// BleScanRuleConfig scanRuleConfig = new BleScanRuleConfig.Builder()
// .setAutoConnect(true)
// .setScanTimeOut(10000)
// .build();
// BleManager.getInstance().initScanRule(scanRuleConfig);
-
- BleManager.getInstance().scan(new BleScanCallback() {
- @Override
- public void onScanStarted(boolean success) {
- showToast("开始蓝牙扫描");
- }
-
- @Override
- public void onScanning(BleDevice bleDevice) {
- showToast("发现设备");
- mLeDeviceListAdapter.addDevice(bleDevice.getDevice());
- mLeDeviceListAdapter.notifyDataSetChanged();
- }
-
- @Override
- public void onScanFinished(List scanResultList) {
- showToast("蓝牙扫描结束");
- showLog(String.valueOf(scanResultList.size()));
- showLog(new Gson().toJson(scanResultList));
- }
- });
- }
+//
+// BleManager.getInstance().scan(new BleScanCallback() {
+// @Override
+// public void onScanStarted(boolean success) {
+// showToast("开始蓝牙扫描");
+// }
+//
+// @Override
+// public void onScanning(BleDevice bleDevice) {
+//// if (context != null && !BlueToothDeviceActivity.this.isFinishing() && !BlueToothDeviceActivity.this.isDestroyed()) {
+//// showToast("发现设备");
+//// }
+// BluetoothDevice device = bleDevice.getDevice();
+// if(device!=null){
+// if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
+// // TODO: Consider calling
+// // ActivityCompat#requestPermissions
+// // here to request the missing permissions, and then overriding
+// // public void onRequestPermissionsResult(int requestCode, String[] permissions,
+// // int[] grantResults)
+// // to handle the case where the user grants the permission. See the documentation
+// // for ActivityCompat#requestPermissions for more details.
+// return;
+// }
+// String deviceName = device.getName();
+// if (deviceName != null && !deviceName.isEmpty()){
+// showLog(new Gson().toJson(device));
+// mLeDeviceListAdapter.addDevice(bleDevice.getDevice());
+// mLeDeviceListAdapter.notifyDataSetChanged();
+// }
+// }
+// }
+//
+// @Override
+// public void onScanFinished(List scanResultList) {
+// if (context != null && !BlueToothDeviceActivity.this.isFinishing() && !BlueToothDeviceActivity.this.isDestroyed()) {
+// showToast("蓝牙扫描结束");
+// }
+// showLog(String.valueOf(mLeDeviceListAdapter.getCount()));
+// showLog(new Gson().toJson(scanResultList));
+// }
+// });
+// }
private void scanLeDevice() {
if (!scanning) {
@@ -238,4 +427,151 @@ public class BlueToothDeviceActivity extends BaseActivity {
}
};
+ private class LeDeviceListAdapter extends BaseAdapter {
+ private class ViewHolder {
+ TextView deviceName;
+ TextView deviceStatus;
+ TextView deviceBind;
+ TextView deviceDeBind;
+ TextView sendData;
+ }
+
+ private ArrayList mLeDevices;
+ private LayoutInflater mInflator;
+ private CallBackBlueToothBind callBackBlueToothBind;
+ private CallBackBlueToothUnBind callBackBlueToothUnBind;
+ private CallBackBlueToothSendData callBackBlueToothSendData;
+
+ public LeDeviceListAdapter(CallBackBlueToothBind callBackBlueToothBind,CallBackBlueToothUnBind callBackBlueToothUnBind,
+ CallBackBlueToothSendData callBackBlueToothSendData) {
+ super();
+ mLeDevices = new ArrayList();
+ mInflator = BlueToothDeviceActivity.this.getLayoutInflater();
+ this.callBackBlueToothBind=callBackBlueToothBind;
+ this.callBackBlueToothUnBind=callBackBlueToothUnBind;
+ this.callBackBlueToothSendData=callBackBlueToothSendData;
+ }
+
+ public interface CallBackBlueToothBind {
+ void Click(int position);
+ }
+
+ public interface CallBackBlueToothUnBind {
+ void Click(int position);
+ }
+
+ public interface CallBackBlueToothSendData {
+ void Click(int position);
+ }
+
+ public void addDevice(BluetoothDevice device) {
+ if (!mLeDevices.contains(device)) {
+ mLeDevices.add(device);
+ }
+ }
+
+ public BluetoothDevice getDevice(int position) {
+ return mLeDevices.get(position);
+ }
+
+ public void clear() {
+ mLeDevices.clear();
+ }
+
+ @Override
+ public int getCount() {
+ return mLeDevices.size();
+ }
+
+ @Override
+ public Object getItem(int i) {
+ return mLeDevices.get(i);
+ }
+
+ @Override
+ public long getItemId(int i) {
+ return i;
+ }
+
+ @Override
+ public View getView(int i, View view, ViewGroup viewGroup) {
+ LeDeviceListAdapter.ViewHolder viewHolder;
+ if (view == null) {
+ view = mInflator.inflate(R.layout.listitem_device, null);
+ viewHolder = new LeDeviceListAdapter.ViewHolder();
+ viewHolder.deviceName = view.findViewById(R.id.device_name);
+ viewHolder.deviceStatus = view.findViewById(R.id.device_status);
+ viewHolder.deviceBind = view.findViewById(R.id.device_bind);
+ viewHolder.deviceDeBind = view.findViewById(R.id.device_de_bind);
+ viewHolder.sendData = view.findViewById(R.id.send_data);
+ view.setTag(viewHolder);
+ } else {
+ viewHolder = (LeDeviceListAdapter.ViewHolder) view.getTag();
+ }
+
+ BluetoothDevice device = mLeDevices.get(i);
+ if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
+ // TODO: Consider calling
+ // ActivityCompat#requestPermissions
+ // here to request the missing permissions, and then overriding
+ // public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ // int[] grantResults)
+ // to handle the case where the user grants the permission. See the documentation
+ // for ActivityCompat#requestPermissions for more details.
+ return null;
+ }
+ String deviceName = device.getName();
+ if (deviceName != null && !deviceName.isEmpty())
+ viewHolder.deviceName.setText(deviceName);
+ else{
+ viewHolder.deviceName.setText(R.string.unknown_device);
+ }
+ //当前点击选中的变色
+ if (i == selectItem) {
+ viewHolder.deviceName.getPaint().setFakeBoldText(true);
+ //viewHolder.deviceName.setTextColor(Color.parseColor("#00FF7F"));//连接之后的颜色
+ viewHolder.deviceStatus.setTextColor(Color.parseColor("#00FF7F"));//连接之后的颜色
+ viewHolder.deviceStatus.setText("已连接");
+ } else {
+ viewHolder.deviceName.getPaint().setFakeBoldText(false);
+ //viewHolder.deviceName.setTextColor(Color.parseColor("#00FF7F"));//连接之后的颜色
+ viewHolder.deviceStatus.setTextColor(Color.parseColor("#000000"));
+ viewHolder.deviceStatus.setText("未绑定");
+ }
+ viewHolder.deviceBind.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if(callBackBlueToothBind!=null){
+ callBackBlueToothBind.Click(i);
+ }
+ }
+ });
+ viewHolder.deviceDeBind.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if(callBackBlueToothUnBind!=null){
+ callBackBlueToothUnBind.Click(i);
+ }
+ }
+ });
+ viewHolder.sendData.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if(callBackBlueToothSendData!=null){
+ callBackBlueToothSendData.Click(i);
+ }
+ }
+ });
+
+
+
+ return view;
+ }
+
+ public void setSelectItem(int selectItem) {
+ this.selectItem = selectItem;
+ }
+
+ private int selectItem = -1;
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/rehome/dywoa/ui/fragment/HomeFragment.java b/app/src/main/java/com/rehome/dywoa/ui/fragment/HomeFragment.java
index a905ca1..92cec60 100755
--- a/app/src/main/java/com/rehome/dywoa/ui/fragment/HomeFragment.java
+++ b/app/src/main/java/com/rehome/dywoa/ui/fragment/HomeFragment.java
@@ -4,6 +4,8 @@ package com.rehome.dywoa.ui.fragment;
import static android.app.Activity.RESULT_OK;
import android.Manifest;
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Environment;
@@ -20,7 +22,11 @@ import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
+import androidx.core.app.ActivityCompat;
+import com.bjzc.blemanager.BleManager;
+import com.bjzc.blemanager.BluetoothLeService;
+import com.google.gson.Gson;
import com.rehome.dywoa.App;
import com.rehome.dywoa.Contans;
import com.rehome.dywoa.MainActivity;
@@ -105,6 +111,8 @@ public class HomeFragment extends BaseFragment {
SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
+ private BleManager ble;
+
//人脸识别
ActivityResultLauncher launcherResultFaceRecognition;
@@ -125,6 +133,45 @@ public class HomeFragment extends BaseFragment {
username = App.getInstance().getUserInfo().getManid();
firstDeparment = App.getInstance().getUserInfo().getFirstDeparment();
+ ble= BleManager.getInstance();
+ String str=ble.init(requireActivity());
+ if("OK".equals(str)){
+
+ }
+
+ ble.setOnReceiveListener(new BleManager.OnReceiveListener() {
+ @Override
+ public void onShowMessage(Context context, Intent intent) {
+ final String action = intent.getAction();
+ if (BluetoothDevice.ACTION_FOUND.equals(action)) {
+ BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ if (ActivityCompat.checkSelfPermission(requireActivity(), Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
+ // TODO: Consider calling
+ // ActivityCompat#requestPermissions
+ // here to request the missing permissions, and then overriding
+ // public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ // int[] grantResults)
+ // to handle the case where the user grants the permission. See the documentation
+ // for ActivityCompat#requestPermissions for more details.
+ return;
+ }
+ showLog("扫描发现设备" + device.getName() + "," + device.getAddress());
+ String deviceName = device.getName();
+ if (deviceName != null && !deviceName.isEmpty()){
+ showLog(new Gson().toJson(device));
+ }
+ } else if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
+ showLog("连接");
+ } else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
+ showLog("断开");
+ } else if (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
+ showLog("数据传输通道准备就绪,可以发送数据了。");
+ } else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
+ byte[] data= intent.getByteArrayExtra(BluetoothLeService.EXTRA_DATA);
+ showLog("收到传感器数据" + new String(data));
+ }
+ }
+ });
//android 10 以上
if (context.getExternalFilesDir(null) != null) {
diff --git a/app/src/main/res/drawable/btn_pressed_bt.xml b/app/src/main/res/drawable/btn_pressed_bt.xml
new file mode 100644
index 0000000..31870a9
--- /dev/null
+++ b/app/src/main/res/drawable/btn_pressed_bt.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/btn_selector_bt.xml b/app/src/main/res/drawable/btn_selector_bt.xml
new file mode 100644
index 0000000..3fc9046
--- /dev/null
+++ b/app/src/main/res/drawable/btn_selector_bt.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_blue_tooth_device.xml b/app/src/main/res/layout/activity_blue_tooth_device.xml
index 1d581d0..018f0da 100644
--- a/app/src/main/res/layout/activity_blue_tooth_device.xml
+++ b/app/src/main/res/layout/activity_blue_tooth_device.xml
@@ -10,7 +10,8 @@
diff --git a/app/src/main/res/layout/listitem_device.xml b/app/src/main/res/layout/listitem_device.xml
index a5cbf17..97806ce 100644
--- a/app/src/main/res/layout/listitem_device.xml
+++ b/app/src/main/res/layout/listitem_device.xml
@@ -5,37 +5,129 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
- android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
+ android:layout_marginEnd="10dp"
android:layout_marginBottom="6dp"
app:cardBackgroundColor="@color/xui_config_color_white"
app:cardCornerRadius="8dp"
app:cardElevation="4dp"
app:cardPreventCornerOverlap="true"
- app:contentPaddingTop="5dp"
- app:contentPaddingBottom="10dp"
+ app:contentPaddingBottom="5dp"
app:contentPaddingLeft="10dp"
- app:contentPaddingRight="10dp">
+ app:contentPaddingRight="10dp"
+ app:contentPaddingTop="5dp">
-
-
-
-
+
+
-
+ android:layout_height="wrap_content"
+ android:baselineAligned="false"
+ android:gravity="center_vertical"
+ android:minHeight="30dp"
+ android:orientation="horizontal">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+