├── .gradle ├── 7.5 │ ├── gc.properties │ ├── fileChanges │ │ └── last-build.bin │ ├── dependencies-accessors │ │ ├── gc.properties │ │ └── dependencies-accessors.lock │ ├── checksums │ │ ├── checksums.lock │ │ ├── md5-checksums.bin │ │ └── sha1-checksums.bin │ ├── fileHashes │ │ ├── fileHashes.bin │ │ └── fileHashes.lock │ └── executionHistory │ │ └── executionHistory.lock ├── vcs-1 │ └── gc.properties ├── buildOutputCleanup │ ├── cache.properties │ ├── outputFiles.bin │ └── buildOutputCleanup.lock └── config.properties ├── app ├── .gitignore ├── keystore │ └── ble.jks ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── list_item.xml │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── hjy │ │ │ │ └── test │ │ │ │ ├── MyApp.java │ │ │ │ ├── Tools.java │ │ │ │ ├── ViewHolder.java │ │ │ │ ├── MyAdapter.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── hjy │ │ │ └── test │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── hjy │ │ └── test │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── BluetoothLib ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── hjy │ │ │ │ └── bluetooth │ │ │ │ ├── inter │ │ │ │ ├── ReceiveCallBack.java │ │ │ │ ├── SendCallBack.java │ │ │ │ ├── BleNotifyCallBack.java │ │ │ │ ├── BleMtuChangedCallback.java │ │ │ │ ├── ClassicBluetoothPairCallBack.java │ │ │ │ ├── ConnectCallBack.java │ │ │ │ └── ScanCallBack.java │ │ │ │ ├── constant │ │ │ │ ├── ValueLimit.java │ │ │ │ ├── ClassicBluetoothPairMode.java │ │ │ │ └── BluetoothState.java │ │ │ │ ├── exception │ │ │ │ └── BluetoothException.java │ │ │ │ ├── operator │ │ │ │ ├── abstra │ │ │ │ │ ├── Receiver.java │ │ │ │ │ ├── Scanner.java │ │ │ │ │ ├── Connector.java │ │ │ │ │ └── Sender.java │ │ │ │ └── impl │ │ │ │ │ ├── BluetoothReceiver.java │ │ │ │ │ ├── BluetoothSender.java │ │ │ │ │ ├── BluetoothScanner.java │ │ │ │ │ └── BluetoothConnector.java │ │ │ │ ├── entity │ │ │ │ ├── ScanFilter.java │ │ │ │ └── BluetoothDevice.java │ │ │ │ ├── utils │ │ │ │ ├── ReceiveHolder.java │ │ │ │ ├── ArrayUtils.java │ │ │ │ ├── LockStore.java │ │ │ │ ├── ScanFilterUtils.java │ │ │ │ └── BleNotifier.java │ │ │ │ ├── async │ │ │ │ ├── WeakAsyncTask.java │ │ │ │ └── ClassicBluetoothConnectTask.java │ │ │ │ └── HBluetooth.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── hjy │ │ │ └── bluetooth │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── hjy │ │ └── bluetooth │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── .idea ├── .gitignore ├── compiler.xml ├── AndroidProjectSystem.xml ├── migrations.xml ├── misc.xml ├── gradle.xml ├── runConfigurations.xml └── workspace.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── local.properties ├── gradlew.bat ├── gradlew └── README.md /.gradle/7.5/gc.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gradle/vcs-1/gc.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /BluetoothLib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /.gradle/7.5/fileChanges/last-build.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gradle/7.5/dependencies-accessors/gc.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':BluetoothLib' 2 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/gradle.properties -------------------------------------------------------------------------------- /app/keystore/ble.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/app/keystore/ble.jks -------------------------------------------------------------------------------- /.gradle/buildOutputCleanup/cache.properties: -------------------------------------------------------------------------------- 1 | #Thu May 22 18:29:59 CST 2025 2 | gradle.version=7.5 3 | -------------------------------------------------------------------------------- /.gradle/config.properties: -------------------------------------------------------------------------------- 1 | #Thu May 22 18:29:40 CST 2025 2 | java.home=C\:\\Program Files\\Java\\jdk-11.0.11 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | HBluetooth 3 | 4 | -------------------------------------------------------------------------------- /.gradle/7.5/checksums/checksums.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/.gradle/7.5/checksums/checksums.lock -------------------------------------------------------------------------------- /.gradle/7.5/fileHashes/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/.gradle/7.5/fileHashes/fileHashes.bin -------------------------------------------------------------------------------- /.gradle/7.5/fileHashes/fileHashes.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/.gradle/7.5/fileHashes/fileHashes.lock -------------------------------------------------------------------------------- /.gradle/7.5/checksums/md5-checksums.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/.gradle/7.5/checksums/md5-checksums.bin -------------------------------------------------------------------------------- /.gradle/7.5/checksums/sha1-checksums.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/.gradle/7.5/checksums/sha1-checksums.bin -------------------------------------------------------------------------------- /BluetoothLib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BluetoothLib 3 | 4 | -------------------------------------------------------------------------------- /.gradle/buildOutputCleanup/outputFiles.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/.gradle/buildOutputCleanup/outputFiles.bin -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.gradle/7.5/executionHistory/executionHistory.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/.gradle/7.5/executionHistory/executionHistory.lock -------------------------------------------------------------------------------- /.gradle/buildOutputCleanup/buildOutputCleanup.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/.gradle/buildOutputCleanup/buildOutputCleanup.lock -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gradle/7.5/dependencies-accessors/dependencies-accessors.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-HJY/HBluetooth/HEAD/.gradle/7.5/dependencies-accessors/dependencies-accessors.lock -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/AndroidProjectSystem.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Mar 05 15:57:32 CST 2025 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /.idea/migrations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/inter/ReceiveCallBack.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.inter; 2 | 3 | import java.io.DataInputStream; 4 | 5 | /** 6 | * Created by _H_JY on 2018/10/24. 7 | */ 8 | 9 | public interface ReceiveCallBack { 10 | 11 | void onReceived(DataInputStream dataInputStream, byte[] result); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/constant/ValueLimit.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.constant; 2 | 3 | /** 4 | * author : HJY 5 | * date : 2021/9/9 6 | * desc : 7 | */ 8 | public final class ValueLimit { 9 | 10 | public static final int DEFAULT_MTU = 23; 11 | 12 | public static final int DEFAULT_MAX_MTU = 512; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/exception/BluetoothException.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.exception; 2 | 3 | /** 4 | * author : HJY 5 | * date : 2021/9/9 6 | * desc : 7 | */ 8 | public class BluetoothException extends Exception { 9 | 10 | 11 | public BluetoothException(String message) { 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/constant/ClassicBluetoothPairMode.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.constant; 2 | 3 | /** 4 | * author : HJY 5 | * date : 2021/11/26 6 | * desc : 7 | */ 8 | public final class ClassicBluetoothPairMode { 9 | 10 | public final static int JUST_WORK = 10; 11 | 12 | public final static int PIN_CODE = 11; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/inter/SendCallBack.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.inter; 2 | 3 | import com.hjy.bluetooth.exception.BluetoothException; 4 | 5 | /** 6 | * Created by _H_JY on 2018/10/24. 7 | */ 8 | 9 | public interface SendCallBack { 10 | 11 | void onSending(byte[] command); 12 | 13 | void onSendFailure(BluetoothException bleException); 14 | } 15 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file must *NOT* be checked into Version Control Systems, 2 | # as it contains information specific to your local configuration. 3 | # 4 | # Location of the SDK. This is only used by Gradle. 5 | # For customization when using a Version Control System, please read the 6 | # header note. 7 | #Thu May 22 18:28:13 CST 2025 8 | sdk.dir=C\:\\Users\\lenovo\\AppData\\Local\\Android\\Sdk 9 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/inter/BleNotifyCallBack.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.inter; 2 | 3 | import com.hjy.bluetooth.exception.BluetoothException; 4 | 5 | /** 6 | * author : HJY 7 | * date : 2021/11/10 8 | * desc : 9 | */ 10 | public interface BleNotifyCallBack { 11 | 12 | void onNotifySuccess(); 13 | 14 | void onNotifyFailure(BluetoothException bleException); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/inter/BleMtuChangedCallback.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.inter; 2 | 3 | import com.hjy.bluetooth.exception.BluetoothException; 4 | 5 | /** 6 | * author : HJY 7 | * date : 2021/9/9 8 | * desc : 9 | */ 10 | public interface BleMtuChangedCallback { 11 | 12 | void onSetMTUFailure(int realMtuSize, BluetoothException bleException); 13 | 14 | void onMtuChanged(int mtuSize); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/operator/abstra/Receiver.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.operator.abstra; 2 | 3 | import com.hjy.bluetooth.inter.ReceiveCallBack; 4 | 5 | 6 | /** 7 | * author : HJY 8 | * date : 2021/11/12 9 | * desc : 10 | */ 11 | public abstract class Receiver { 12 | public abstract void setReceiveCallBack(ReceiveCallBack receiveCallBack); 13 | public abstract ReceiveCallBack getReceiveCallBack(); 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/constant/BluetoothState.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.constant; 2 | 3 | /** 4 | * Created by _H_JY on 2018/10/23. 5 | */ 6 | 7 | public final class BluetoothState { 8 | 9 | public final static int PAIRED_FAILED = 0; 10 | 11 | public final static int CONNECT_SUCCESS = 1; 12 | 13 | public final static int CONNECT_FAIL = 2; 14 | 15 | public final static int CONNECT_TIMEOUT = 3; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/inter/ClassicBluetoothPairCallBack.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.inter; 2 | 3 | import com.hjy.bluetooth.exception.BluetoothException; 4 | 5 | /** 6 | * author : HJY 7 | * date : 2021/11/26 8 | * desc : 9 | */ 10 | public interface ClassicBluetoothPairCallBack { 11 | 12 | void onPairSuccess(); 13 | void onPairing(); 14 | void onPairFailure(BluetoothException bluetoothException); 15 | void onPairRemoved(); 16 | } 17 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/inter/ConnectCallBack.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.inter; 2 | 3 | import com.hjy.bluetooth.operator.abstra.Sender; 4 | 5 | /** 6 | * Created by _H_JY on 2018/10/20. 7 | */ 8 | public interface ConnectCallBack { 9 | 10 | void onConnecting(); 11 | 12 | void onConnected(Sender sender); 13 | 14 | void onDisConnecting(); 15 | 16 | void onDisConnected(); 17 | 18 | void onError(int errorType,String errorMsg); 19 | } 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | -------------------------------------------------------------------------------- /app/src/test/java/com/hjy/test/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.hjy.test; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /BluetoothLib/src/test/java/com/hjy/bluetooth/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/java/com/hjy/test/MyApp.java: -------------------------------------------------------------------------------- 1 | package com.hjy.test; 2 | 3 | import android.app.Application; 4 | 5 | import com.hjy.bluetooth.HBluetooth; 6 | 7 | /** 8 | * author : HJY 9 | * date : 2021/11/12 10 | * desc : 11 | */ 12 | public class MyApp extends Application { 13 | 14 | @Override 15 | public void onCreate() { 16 | super.onCreate(); 17 | //初始化 HBluetooth 18 | HBluetooth.init(this); 19 | HBluetooth.getInstance() 20 | .setConnectTimeOut(10000); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/inter/ScanCallBack.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.inter; 2 | 3 | import com.hjy.bluetooth.entity.BluetoothDevice; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by _H_JY on 2018/10/20. 9 | */ 10 | public interface ScanCallBack { 11 | 12 | void onScanStart(); 13 | 14 | void onScanning(List scannedDevices,BluetoothDevice currentScannedDevice); 15 | 16 | void onError(int errorType,String errorMsg); 17 | 18 | void onScanFinished(List bluetoothDevices); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/entity/ScanFilter.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.entity; 2 | 3 | /** 4 | * author : HJY 5 | * date : 2021/11/15 6 | * desc : 7 | */ 8 | public class ScanFilter { 9 | 10 | private boolean fuzzyMatching; 11 | 12 | private String[] names; 13 | 14 | private ScanFilter(){} 15 | 16 | public ScanFilter(boolean fuzzyMatching, String... names) { 17 | this.fuzzyMatching = fuzzyMatching; 18 | this.names = names; 19 | } 20 | 21 | public boolean isFuzzyMatching() { 22 | return fuzzyMatching; 23 | } 24 | 25 | public String[] getNames() { 26 | return names; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/hjy/test/Tools.java: -------------------------------------------------------------------------------- 1 | package com.hjy.test; 2 | 3 | /** 4 | * Created by _H_JY on 2019/3/7. 5 | */ 6 | public class Tools { 7 | 8 | public static String bytesToHexString(byte[] src) { 9 | StringBuilder stringBuilder = new StringBuilder(""); 10 | if (src == null || src.length <= 0) { 11 | return null; 12 | } 13 | for (int i = 0; i < src.length; i++) { 14 | int v = src[i] & 0xFF; 15 | String hv = Integer.toHexString(v); 16 | if (hv.length() < 2) { 17 | stringBuilder.append(0); 18 | } 19 | stringBuilder.append(hv + " "); 20 | } 21 | return stringBuilder.toString().toUpperCase(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/operator/abstra/Scanner.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.operator.abstra; 2 | 3 | import com.hjy.bluetooth.entity.ScanFilter; 4 | import com.hjy.bluetooth.inter.ScanCallBack; 5 | 6 | /** 7 | * Created by _H_JY on 2018/10/20. 8 | */ 9 | public abstract class Scanner { 10 | 11 | private ScanFilter filter; 12 | 13 | public abstract void scan(int scanType, ScanCallBack scanCallBack); 14 | 15 | public abstract void scan(int scanType, int timeUse, ScanCallBack scanCallBack); 16 | 17 | public abstract void stopScan(); 18 | 19 | public abstract void resetCallBack(); 20 | 21 | public ScanFilter getFilter() { 22 | return filter; 23 | } 24 | 25 | public void setFilter(ScanFilter filter) { 26 | this.filter = filter; 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /BluetoothLib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/hjy/test/ViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.hjy.test; 2 | 3 | import android.util.SparseArray; 4 | import android.view.View; 5 | 6 | /** 7 | * Created by Administrator on 2018/10/24. 8 | */ 9 | 10 | public class ViewHolder { 11 | 12 | public static T getView(View convertView, int childViewId) { 13 | SparseArray viewHolder = (SparseArray) convertView.getTag(); 14 | if (viewHolder == null) { 15 | viewHolder = new SparseArray<>(); 16 | convertView.setTag(viewHolder); 17 | } 18 | 19 | View childView = viewHolder.get(childViewId); 20 | if (childView == null) { 21 | childView = convertView.findViewById(childViewId); 22 | viewHolder.put(childViewId, childView); 23 | } 24 | 25 | return (T) childView; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/hjy/test/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.hjy.test; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.hjy.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /BluetoothLib/src/androidTest/java/com/hjy/bluetooth/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.hjy.hardwarehost.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /BluetoothLib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdk 33 5 | 6 | defaultConfig { 7 | minSdk 18 8 | targetSdk 33 9 | versionCode 1 10 | versionName "1.0" 11 | 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | 28 | implementation 'com.android.support:appcompat-v7:28.0.0' 29 | testImplementation 'junit:junit:4.12' 30 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 31 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 32 | } 33 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 17 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/operator/abstra/Connector.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.operator.abstra; 2 | 3 | import com.hjy.bluetooth.entity.BluetoothDevice; 4 | import com.hjy.bluetooth.inter.BleNotifyCallBack; 5 | import com.hjy.bluetooth.inter.ClassicBluetoothPairCallBack; 6 | import com.hjy.bluetooth.inter.ConnectCallBack; 7 | 8 | /** 9 | * Created by _H_JY on 2018/10/20. 10 | */ 11 | public abstract class Connector { 12 | 13 | private int retryTimes; 14 | 15 | public abstract void connect(BluetoothDevice device, ConnectCallBack connectCallBack); 16 | 17 | public abstract void connect(BluetoothDevice device, ClassicBluetoothPairCallBack classicBluetoothPairCallBack, ConnectCallBack connectCallBack); 18 | 19 | public abstract void connect(BluetoothDevice device, ConnectCallBack connectCallBack, BleNotifyCallBack notifyCallBack); 20 | 21 | public int getRetryTimes() { 22 | return retryTimes; 23 | } 24 | 25 | public void setRetryTimes(int retryTimes) { 26 | this.retryTimes = retryTimes; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/operator/abstra/Sender.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.operator.abstra; 2 | 3 | import com.hjy.bluetooth.inter.ConnectCallBack; 4 | import com.hjy.bluetooth.inter.SendCallBack; 5 | 6 | /** 7 | * Created by _H_JY on 2018/10/22. 8 | */ 9 | public abstract class Sender { 10 | 11 | public abstract void send(byte[] command, SendCallBack sendCallBack); 12 | 13 | public abstract T initChannel(T o, int type, ConnectCallBack connectCallBack); 14 | 15 | public abstract void discoverServices(); 16 | 17 | public abstract G initSenderHelper(G g); 18 | 19 | public abstract void destroyChannel(); 20 | 21 | public abstract void resetCallBack(); 22 | 23 | 24 | /** 25 | * Read characteristic according to the service uuid and characteristic uuid 26 | * 27 | * @param serviceUUID 28 | * @param characteristicUUID 29 | * @param sendCallBack 30 | */ 31 | public abstract void readCharacteristic(String serviceUUID, String characteristicUUID, SendCallBack sendCallBack); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/utils/ReceiveHolder.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.utils; 2 | 3 | import android.bluetooth.BluetoothGattCharacteristic; 4 | 5 | import com.hjy.bluetooth.HBluetooth; 6 | import com.hjy.bluetooth.operator.abstra.Receiver; 7 | 8 | import java.io.DataInputStream; 9 | 10 | /** 11 | * author : HJY 12 | * date : 2021/11/17 13 | * desc : 14 | */ 15 | public class ReceiveHolder { 16 | 17 | public static void receiveBleReturnData(BluetoothGattCharacteristic characteristic) { 18 | byte[] result = characteristic.getValue(); 19 | Receiver receiver = HBluetooth.getInstance().receiver(); 20 | if (receiver != null && receiver.getReceiveCallBack() != null) { 21 | receiver.getReceiveCallBack().onReceived(null, result); 22 | } 23 | } 24 | 25 | public static void receiveClassicBluetoothReturnData(DataInputStream dis, byte[] result) { 26 | Receiver receiver = HBluetooth.getInstance().receiver(); 27 | if (receiver != null && receiver.getReceiveCallBack() != null) { 28 | receiver.getReceiveCallBack().onReceived(dis, result); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/res/layout/list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 15 | 16 | 17 | 26 | 27 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /BluetoothLib/src/main/java/com/hjy/bluetooth/utils/ArrayUtils.java: -------------------------------------------------------------------------------- 1 | package com.hjy.bluetooth.utils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * author : HJY 8 | * date : 2021/11/12 9 | * desc : 10 | */ 11 | public class ArrayUtils { 12 | 13 | /** 14 | * splitAry方法
15 | * @param ary 要分割的数组 16 | * @param subSize 分割的块大小 17 | * @return 18 | * 19 | */ 20 | public static Object[] splitBytes(byte[] ary, int subSize) { 21 | int count = ary.length % subSize == 0 ? ary.length / subSize: ary.length / subSize + 1; 22 | 23 | List> subAryList = new ArrayList<>(); 24 | 25 | for (int i = 0; i < count; i++) { 26 | int index = i * subSize; 27 | List list = new ArrayList<>(); 28 | int j = 0; 29 | while (j < subSize && index < ary.length) { 30 | list.add(ary[index++]); 31 | j++; 32 | } 33 | subAryList.add(list); 34 | } 35 | 36 | Object[] subAry = new Object[subAryList.size()]; 37 | 38 | for(int i = 0; i < subAryList.size(); i++){ 39 | List subList = subAryList.get(i); 40 | byte[] subAryItem = new byte[subList.size()]; 41 | for(int j = 0; j < subList.size(); j++){ 42 | subAryItem[j] = subList.get(j); 43 | } 44 | subAry[i] = subAryItem; 45 | } 46 | 47 | return subAry; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 15 | 16 |