├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── activity_service.xml │ │ │ │ └── activity_client.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── xloong │ │ │ │ └── bluetoothsocketdemo │ │ │ │ ├── GlideLoader.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── BaseActivity.java │ │ │ │ ├── ServiceActivity.java │ │ │ │ └── ClientActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── xloong │ │ │ └── bluetoothsocketdemo │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── xloong │ │ └── bluetoothsocketdemo │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── library_bluesocket ├── .gitignore ├── src │ ├── main │ │ ├── aidl │ │ │ ├── android │ │ │ │ └── bluetooth │ │ │ │ │ └── BluetoothDevice.aidl │ │ │ └── com │ │ │ │ └── xloong │ │ │ │ └── library │ │ │ │ └── bluesocket │ │ │ │ └── IBluetooth.aidl │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── xloong │ │ │ └── library │ │ │ └── bluesocket │ │ │ ├── BlueMessageReceiver.java │ │ │ ├── BlueClientThread.java │ │ │ ├── message │ │ │ ├── IMessage.java │ │ │ ├── StringMessage.java │ │ │ └── ImageMessage.java │ │ │ ├── BlueServiceThread.java │ │ │ ├── BlueSocketBaseThread.java │ │ │ ├── utils │ │ │ └── TypeUtils.java │ │ │ ├── BlueManager.java │ │ │ ├── BlueService.java │ │ │ ├── BlueDataThread.java │ │ │ └── BluetoothSppHelper.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── xloong │ │ │ └── library │ │ │ └── bluesocket │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── xloong │ │ └── library │ │ └── bluesocket │ │ └── ApplicationTest.java ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── .github └── workflows │ └── gradle.yml ├── gradle.properties ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library_bluesocket/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':library_bluesocket' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnlbxb2004/BluetoothSocket/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BluetoothSocketDemo 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnlbxb2004/BluetoothSocket/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnlbxb2004/BluetoothSocket/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnlbxb2004/BluetoothSocket/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnlbxb2004/BluetoothSocket/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnlbxb2004/BluetoothSocket/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /library_bluesocket/src/main/aidl/android/bluetooth/BluetoothDevice.aidl: -------------------------------------------------------------------------------- 1 | // BluetoothDevice.aidl 2 | package android.bluetooth; 3 | parcelable BluetoothDevice; 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/test/java/com/xloong/bluetoothsocketdemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.xloong.bluetoothsocketdemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /library_bluesocket/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 19 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | 14 | } 15 | 16 | dependencies { 17 | compile fileTree(dir: 'libs', include: ['*.jar']) 18 | testCompile 'junit:junit:4.12' 19 | 20 | } 21 | -------------------------------------------------------------------------------- /library_bluesocket/src/test/java/com/xloong/library/bluesocket/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.xloong.library.bluesocket; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/xloong/bluetoothsocketdemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.xloong.bluetoothsocketdemo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /library_bluesocket/src/androidTest/java/com/xloong/library/bluesocket/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.xloong.library.bluesocket; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /library_bluesocket/src/main/aidl/com/xloong/library/bluesocket/IBluetooth.aidl: -------------------------------------------------------------------------------- 1 | // IBluetooth.aidl 2 | package com.xloong.library.bluesocket; 3 | 4 | import android.bluetooth.BluetoothDevice; 5 | 6 | // Declare any non-default types here with import statements 7 | 8 | interface IBluetooth { 9 | // 蓝牙是否连接 10 | boolean isConnected(); 11 | 12 | //启动service 端 startService 和 connectionService只能用一个。 13 | void startService(); 14 | 15 | //连接Service 端 startService 和 connectionService只能用一个。 16 | void connectionService(in BluetoothDevice device); 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /library_bluesocket/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Java CI with Gradle 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up JDK 1.8 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 1.8 23 | - name: Grant execute permission for gradlew 24 | run: chmod +x gradlew 25 | - name: Build with Gradle 26 | run: ./gradlew build 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/xloong/bluetoothsocketdemo/GlideLoader.java: -------------------------------------------------------------------------------- 1 | package com.xloong.bluetoothsocketdemo; 2 | 3 | import android.content.Context; 4 | import android.widget.ImageView; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.jaiky.imagespickers.ImageLoader; 8 | 9 | /** 10 | * Created by xubingbing on 2017/8/10. 11 | */ 12 | 13 | public class GlideLoader implements ImageLoader { 14 | 15 | @Override 16 | public void displayImage(Context context, String path, ImageView imageView) { 17 | Glide.with(context) 18 | .load(path) 19 | .placeholder(com.jaiky.imagespickers.R.drawable.global_img_default) 20 | .centerCrop() 21 | .into(imageView); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/bingbing/Documents/tools/sdk/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/xloong/bluetoothsocketdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.xloong.bluetoothsocketdemo; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | public class MainActivity extends AppCompatActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_main); 14 | } 15 | 16 | public void client(View view){ 17 | startActivity(new Intent(this, ClientActivity.class)); 18 | } 19 | 20 | public void service(View view){ 21 | startActivity(new Intent(this,ServiceActivity.class)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /library_bluesocket/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/bingbing/Documents/tools/sdk/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 |