Commit 4e74f69f by 韩飞虎

能运行但是不知道啥版本

parent 297b65d7
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/drawable/black_thumb.xml" value="0.20989583333333334" />
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/drawable/gray_thumb.xml" value="0.20989583333333334" />
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/layout/activity_add_device.xml" value="0.19375" />
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/layout/activity_main.xml" value="0.19375" />
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/layout/activity_music.xml" value="0.19375" />
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/layout/activity_play.xml" value="0.19375" />
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/layout/activity_searching.xml" value="0.19375" />
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/layout/activity_seleclt_device.xml" value="0.19375" />
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/layout/activity_select_timer.xml" value="0.19375" />
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/layout/activity_setting_music.xml" value="0.19375" />
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/layout/music_type.xml" value="0.19375" />
<entry key="..\:/程序项目/蓝牙app/BluToysApplication/app/src/main/res/layout/pickerview_custom_time.xml" value="0.19375" />
</map>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
......
apply plugin: 'com.android.library'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 32
buildToolsVersion '30.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 30
targetSdkVersion 32
}
buildTypes {
release {
......
......@@ -4,10 +4,12 @@
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="30" />
android:targetSdkVersion="32" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
BLUETOOTH_SCAN
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
......
<<<<<<< HEAD
#Sat Dec 18 08:49:53 CST 2021
=======
#Sat May 22 18:28:17 CST 2021
>>>>>>> ee610bcfe666c5a8aee5df89f5948dec147a6d1f
#Sat Dec 18 09:10:09 CST 2021
......@@ -5,7 +5,7 @@
5 <uses-sdk
6 android:minSdkVersion="14"
6-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml
7 android:targetSdkVersion="30" />
7 android:targetSdkVersion="32" />
7-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml
8
9 <uses-permission android:name="android.permission.BLUETOOTH" />
......@@ -14,11 +14,15 @@
10 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
10-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:5:5-74
10-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:5:22-71
11 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
11-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:6:5-81
11-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:6:22-78
12 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
12-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:7:5-79
12-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:7:22-76
13
14</manifest>
11 <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
11-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:6:5-76
11-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:6:22-73
12 BLUETOOTH_SCAN
13 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
13-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:8:5-81
13-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:8:22-78
14 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
14-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:9:5-79
14-->D:\程序项目\蓝牙app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:9:22-76
15
16</manifest>
......@@ -4,10 +4,12 @@
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="30" />
android:targetSdkVersion="32" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
BLUETOOTH_SCAN
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
......
-- Merging decision tree log ---
manifest
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:1:1-9:12
INJECTED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:1:1-9:12
INJECTED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:1:1-9:12
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:1:1-11:12
INJECTED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:1:1-11:12
INJECTED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:1:1-11:12
package
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:2:5-30
INJECTED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml
......@@ -17,14 +17,18 @@ uses-permission#android.permission.BLUETOOTH_ADMIN
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:5:5-74
android:name
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:5:22-71
uses-permission#android.permission.BLUETOOTH_CONNECT
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:6:5-76
android:name
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:6:22-73
uses-permission#android.permission.ACCESS_COARSE_LOCATION
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:6:5-81
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:8:5-81
android:name
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:6:22-78
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:8:22-78
uses-permission#android.permission.ACCESS_FINE_LOCATION
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:7:5-79
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:9:5-79
android:name
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:7:22-76
ADDED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml:9:22-76
uses-sdk
INJECTED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml reason: use-sdk injection requested
INJECTED from D:\Ŀ\app\BluToysApplication\FastBleLib\src\main\AndroidManifest.xml
......
......@@ -6,8 +6,8 @@ com/clj/fastble/data/BleWriteState.java
com.clj.fastble.data.BleWriteState
com/clj/fastble/data/BleConnectStateParameter.java
com.clj.fastble.data.BleConnectStateParameter
com/clj/fastble/callback/BleWriteCallback.java
com.clj.fastble.callback.BleWriteCallback
com/clj/fastble/callback/BleScanAndConnectCallback.java
com.clj.fastble.callback.BleScanAndConnectCallback
com/clj/fastble/exception/GattException.java
com.clj.fastble.exception.GattException
com/clj/fastble/callback/BleRssiCallback.java
......@@ -19,8 +19,8 @@ com/clj/fastble/data/BleScanState.java
com.clj.fastble.data.BleScanState
com/clj/fastble/callback/BleBaseCallback.java
com.clj.fastble.callback.BleBaseCallback
com/clj/fastble/exception/OtherException.java
com.clj.fastble.exception.OtherException
com/clj/fastble/callback/BleGattCallback.java
com.clj.fastble.callback.BleGattCallback
com/clj/fastble/utils/BleLog.java
com.clj.fastble.utils.BleLog
com/clj/fastble/callback/BleNotifyCallback.java
......@@ -37,10 +37,14 @@ com/clj/fastble/exception/ConnectException.java
com.clj.fastble.exception.ConnectException
com/clj/fastble/exception/BleException.java
com.clj.fastble.exception.BleException
com/clj/fastble/exception/TimeoutException.java
com.clj.fastble.exception.TimeoutException
com/clj/fastble/data/BleMsg.java
com.clj.fastble.data.BleMsg
com/clj/fastble/scan/BleScanner.java
com.clj.fastble.scan.BleScanner
com.clj.fastble.scan.BleScanner$1
com.clj.fastble.scan.BleScanner$1$1
com.clj.fastble.scan.BleScanner$BleScannerHolder
com/clj/fastble/BleManager.java
com.clj.fastble.BleManager
com.clj.fastble.BleManager$BleManagerHolder
com/clj/fastble/bluetooth/SplitWriter.java
com.clj.fastble.bluetooth.SplitWriter
com.clj.fastble.bluetooth.SplitWriter$1
......@@ -50,21 +54,16 @@ com/clj/fastble/bluetooth/BleBluetooth.java
com.clj.fastble.bluetooth.BleBluetooth$1
com.clj.fastble.bluetooth.BleBluetooth$LastState
com.clj.fastble.bluetooth.BleBluetooth$MainHandler
com/clj/fastble/callback/BleScanAndConnectCallback.java
com.clj.fastble.callback.BleScanAndConnectCallback
com/clj/fastble/data/BleMsg.java
com.clj.fastble.data.BleMsg
com/clj/fastble/callback/BleWriteCallback.java
com.clj.fastble.callback.BleWriteCallback
com/clj/fastble/bluetooth/MultipleBluetoothController.java
com.clj.fastble.bluetooth.MultipleBluetoothController
com.clj.fastble.bluetooth.MultipleBluetoothController$1
com/clj/fastble/scan/BleScanner.java
com.clj.fastble.scan.BleScanner
com.clj.fastble.scan.BleScanner$1
com.clj.fastble.scan.BleScanner$1$1
com.clj.fastble.scan.BleScanner$BleScannerHolder
com/clj/fastble/bluetooth/BleConnector.java
com.clj.fastble.bluetooth.BleConnector
com.clj.fastble.bluetooth.BleConnector$1
com/clj/fastble/callback/BleGattCallback.java
com.clj.fastble.callback.BleGattCallback
com/clj/fastble/scan/BleScanPresenter.java
com.clj.fastble.scan.BleScanPresenter
com.clj.fastble.scan.BleScanPresenter$1
......@@ -74,6 +73,10 @@ com/clj/fastble/scan/BleScanPresenter.java
com.clj.fastble.scan.BleScanPresenter$5
com.clj.fastble.scan.BleScanPresenter$6
com.clj.fastble.scan.BleScanPresenter$ScanHandler
com/clj/fastble/exception/TimeoutException.java
com.clj.fastble.exception.TimeoutException
com/clj/fastble/exception/OtherException.java
com.clj.fastble.exception.OtherException
com/clj/fastble/callback/BleScanPresenterImp.java
com.clj.fastble.callback.BleScanPresenterImp
com/clj/fastble/data/BleDevice.java
......@@ -81,6 +84,3 @@ com/clj/fastble/data/BleDevice.java
com.clj.fastble.data.BleDevice$1
com/clj/fastble/callback/BleScanCallback.java
com.clj.fastble.callback.BleScanCallback
com/clj/fastble/BleManager.java
com.clj.fastble.BleManager
com.clj.fastble.BleManager$BleManagerHolder
......@@ -3,6 +3,8 @@
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
BLUETOOTH_SCAN
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
......
......@@ -2,17 +2,20 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
buildToolsVersion '30.0.2'
defaultConfig {
applicationId "com.stoplight.blu.toys"
minSdkVersion 19
targetSdkVersion 30
targetSdkVersion 32
versionCode 2
versionName "1.2"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
applicationIdSuffix 'dev'
versionNameSuffix 'dev'
signingConfig signingConfigs.debug
}
lintOptions {
......@@ -21,39 +24,34 @@ android {
// but continue the build even whenerrorsarefound:
abortOnError false
}
buildTypes {
debug {
applicationIdSuffix 'com.stoplight.blu.toys'
versionNameSuffix '1.0'
debuggable true
jniDebuggable false
renderscriptDebuggable false
renderscriptOptimLevel 3
signingConfig signingConfigs.debug
minifyEnabled true
multiDexEnabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
applicationIdSuffix 'com.stoplight.blu.toys'
}
}
buildTypes {
buildTypes {
debug {
buildConfigField "int", "myInt", "0"
buildConfigField "String", "myStr", "\"hello\""
buildConfigField "boolean", "LOG_DEBUG", "true"
}
release {
buildConfigField "int", "myInt", "1"
buildConfigField "String", "myStr", "\"world\""
buildConfigField "boolean", "LOG_DEBUG", "false"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility targetCompatibility
targetCompatibility targetCompatibility
}
}
......@@ -66,23 +64,23 @@ dependencies {
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation 'com.squareup.okhttp3:okhttp:4.8.1'
implementation 'com.squareup.okhttp3:logging-interceptor:4.8.1'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.3'
implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.3'
implementation 'com.google.code.gson:gson:2.8.9'
// //数据传递
implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'com.hjq:xxpermissions:8.6'
implementation "androidx.multidex:multidex:2.0.0"
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
......@@ -99,12 +97,12 @@ dependencies {
//底部导航
implementation 'com.roughike:bottom-bar:2.3.1'
// //findViewById
implementation 'com.jakewharton:butterknife:10.2.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
//跑马灯
implementation 'com.superluo:textbannerview:1.0.5' //最新版本
//design
implementation "com.google.android.material:material:1.2.1"
implementation 'com.google.android.material:material:1.3.0'
//万能适配器
// implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.22'
//二维码
......@@ -120,10 +118,11 @@ dependencies {
// implementation 'com.wx.wheelview:wheelview:1.3.3'
//工具类
implementation 'com.blankj:utilcodex:1.28.0'
implementation 'com.alibaba:fastjson:1.2.73'
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'com.orhanobut:logger:1.15'
implementation 'com.blankj:utilcodex:1.31.0'
implementation 'com.alibaba:fastjson:1.2.78'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.orhanobut:logger:2.2.0'
implementation 'top.zibin:Luban:1.1.8'
implementation 'com.yhd.hdbluetooth:hdbluetooth:1.0.0'
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.stoplight.blu.toys">
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
......@@ -23,8 +24,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
......@@ -52,15 +52,20 @@
<activity android:name="com.stoplight.blu.toys.activity.SelectDeviceActivity" />
<activity android:name="com.stoplight.blu.toys.activity.SearchingActivity" />
<activity android:name="com.stoplight.blu.toys.activity.AddDeviceActivity" />
<activity android:name="com.stoplight.blu.toys.MainActivity">
<activity android:name="com.stoplight.blu.toys.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.stoplight.blu.toys.ble.MyService"
android:enabled="true"
android:exported="true"></service>
<receiver android:name="com.stoplight.blu.toys.ble.receiver.BluetoothOpenAndClose">
<receiver android:name="com.stoplight.blu.toys.ble.receiver.BluetoothOpenAndClose"
android:exported="false">
<intent-filter>
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
</intent-filter>
......
package com.stoplight.blu.toys;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
......@@ -7,6 +8,7 @@ import com.stoplight.blu.toys.R;
import com.stoplight.blu.toys.activity.AddDeviceActivity;
import com.stoplight.blu.toys.activity.BaseActivity;
import com.stoplight.blu.toys.app.AppManager;
import com.stoplight.blu.toys.ble.MyService;
public class MainActivity extends BaseActivity {
......@@ -19,6 +21,11 @@ public class MainActivity extends BaseActivity {
@Override
public void init(Bundle savedInstanceState) {
new Handler().postDelayed(() -> {
Intent intent = new Intent(this, MyService.class); this.startService(intent);
goActivity(AddDeviceActivity.class);
AppManager.getInstance().finishActivity();
}, 1000); //延时1s执行
......
......@@ -30,7 +30,7 @@ public abstract class BaseActivity extends AppCompatActivity {
protected static final int PERMISSION_REQUEST = 1001;
private List<String> permissionsList = new ArrayList<>();
private String[] permissions = new String[]{Manifest.permission.CAMERA,
private String[] permissions = new String[]{
Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE};
......@@ -47,7 +47,7 @@ public abstract class BaseActivity extends AppCompatActivity {
private void checkPermission() {
XXPermissions.with(this) // 申请安装包权限
.permission(Permission.CAMERA, Permission.ACCESS_FINE_LOCATION, Permission.ACCESS_FINE_LOCATION) // 申请多个权限
.permission( Permission.ACCESS_FINE_LOCATION, Permission.ACCESS_FINE_LOCATION) // 申请多个权限
.request(new OnPermission() {
@Override
public void hasPermission(List<String> granted, boolean all) {
......
package com.stoplight.blu.toys.activity;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.le.AdvertiseSettings;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
......@@ -12,9 +16,13 @@ import com.stoplight.blu.toys.R;
import com.stoplight.blu.toys.adapter.BleDeviceAdapter;
import com.stoplight.blu.toys.app.AppManager;
import com.stoplight.blu.toys.ble.BlePlay;
import com.stoplight.blu.toys.ble.MyService;
import com.stoplight.blu.toys.ble.inter.IBlePeripheralCallback;
import com.stoplight.blu.toys.utils.BlePeripheralHelper;
import com.stoplight.blu.toys.view.TypefaceTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Logger;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
......@@ -53,8 +61,19 @@ public class SelectDeviceActivity extends BaseActivity {
@Override
public void initData() {
bleDeviceAdapter.setOnItemClickListener((adapter, view, position) -> {
BleDevice bleDevice = (BleDevice) adapter.getItem(position);
BleDevice bleDevice = (BleDevice) adapter.getItem(position);
BlePlay.getInstance().connectedBleDevice(bleDevice);
System.out.println(bleDevice.getShowName());
//Intent intent = new Intent(SelectDeviceActivity.this, MyService.class);
//startService(intent);
});
showBleDevices();
}
......
......@@ -22,7 +22,7 @@ public class BleDeviceAdapter extends BaseQuickAdapter<BleDevice, BaseViewHolder
@Override
protected void convert(BaseViewHolder helper, BleDevice item) {
String deviceName = item.getName();
if ((!TextUtils.isEmpty(deviceName) && deviceName.contains("Traffic"))||!TextUtils.isEmpty(deviceName) && deviceName.contains("blector")) {
if ((!TextUtils.isEmpty(deviceName) && deviceName.contains("Traffic"))||!TextUtils.isEmpty(deviceName) && deviceName.contains("Traffic")) {
helper.setText(R.id.dv_name, item.getShowName() + "");
}
}
......
package com.stoplight.blu.toys.ble;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.util.Log;
import com.blankj.utilcode.util.LogUtils;
import com.clj.fastble.BleManager;
......@@ -189,6 +191,27 @@ public class BlePlay {
}
/* public boolean pair(BluetoothDevice device) {
String TAG="pair";
// Stops the discovery and then creates the pairing.
if (bluetooth.isDiscovering()) {
Log.d(TAG, "Bluetooth cancelling discovery.");
bluetooth.cancelDiscovery();
}
Log.d(TAG, "Bluetooth bonding with device: " + device.getName());
boolean outcome = device.createBond();
Log.d(TAG, "Bounding outcome : " + outcome);
// If the outcome is true, we are bounding with this device.
if (outcome == true) {
this.boundingDevice = device;
}
return outcome;
}*/
/**
* 暂停
*/
......
package com.stoplight.blu.toys.ble;
import android.app.IntentService;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.le.AdvertiseSettings;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import androidx.annotation.Nullable;
import com.stoplight.blu.toys.ble.inter.IBlePeripheralCallback;
import com.stoplight.blu.toys.ble.receiver.BluetoothOpenAndClose;
import com.stoplight.blu.toys.utils.BlePeripheralHelper;
public class MyService extends Service {
IntentFilter connectedFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
public MyService() {
System.out.println("--------------------MyService");
}
public BlePeripheralHelper mBlePeripheralHelper ;
private BluetoothOpenAndClose bluetoothOpenAndClose;
@Override
public void onCreate() {
// TODO Auto-generated method stub
mBlePeripheralHelper= BlePeripheralHelper.getInstance(this);
connectedFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
bluetoothOpenAndClose=new BluetoothOpenAndClose();
registerReceiver(bluetoothOpenAndClose,connectedFilter);
System.out.println("--------------------onCreate");
startBle();
super.onCreate();
}
@Override
public ComponentName startService(Intent service) {
startBle();
System.out.println("--------------------startService");
return super.startService(service);
}
@Override
public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
System.out.println("--------------------onStartCommand");
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
// unregisterReceiver(bluetoothOpenAndClose);
// registerReceiver(bluetoothOpenAndClose,connectedFilter);
mBlePeripheralHelper= BlePeripheralHelper.getInstance(this);
System.out.println("--------------------onDestroy");
Intent localIntent = new Intent(this, MyService.class);
this.startService(localIntent);
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
System.out.println("--------------------intent");
return null;
}
public void startBle(){
if (mBlePeripheralHelper.isBleEnabled()){
// 设置回调
System.out.println("--------------------startBle");
mBlePeripheralHelper.setBlePeripheralCallback(new IBlePeripheralCallback() {
//连接状态回调
@Override
public void onConnectionStateChange(BluetoothDevice bluetoothDevice, int i, int i1) {
System.out.println(bluetoothDevice);
}
//开启广播成功回调
@Override
public void onStartAbSuccess(AdvertiseSettings advertiseSettings) {
System.out.println(advertiseSettings);
}
//开启广失败的功回调
@Override
public void onStartAbFailure(int i) {
System.out.println(i);
}
//收到BLE数据回调
@Override
public void onReceiveNewBytes(BluetoothDevice bluetoothDevice, int i, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bytes) {
System.out.println(bluetoothDevice);
}
//发送BLE数据回调
@Override
public void onWriteBytesAndStatus(boolean b, byte[] bytes) {
System.out.println(bytes);
}
});
// 初始化广播
mBlePeripheralHelper.initGATTServer();
}
}
}
package com.stoplight.blu.toys.ble.inter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.le.AdvertiseSettings;
/**
* Created by Roy.lee
* On 2021/6/27
* Email: 631934797@qq.com
* Description:
*/
public interface IBlePeripheralCallback {
/**
* Connection status callback
*
* @param device
* @param status
* @param newState
*/
void onConnectionStateChange(BluetoothDevice device, int status, int newState);
/**
* Advertise success callback
*
* @param settingsInEffect
*/
void onStartAbSuccess(AdvertiseSettings settingsInEffect);
/**
* Advertise failure callback
*
* @param errorCode
*/
void onStartAbFailure(int errorCode);
/**
* Receive new data callback
*
* @param device
* @param requestId
* @param characteristic
*/
void onReceiveNewBytes(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, byte[] reqeustBytes);
/**
* Send data status callback
* @param status
* @param bytes
*/
void onWriteBytesAndStatus(boolean status, byte[] bytes);
}
package com.stoplight.blu.toys.ble.receiver;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.le.AdvertiseSettings;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
......@@ -9,6 +12,9 @@ import com.blankj.utilcode.util.LogUtils;
import com.clj.fastble.BleManager;
import com.clj.fastble.callback.BleScanCallback;
import com.clj.fastble.data.BleDevice;
import com.stoplight.blu.toys.ble.MyService;
import com.stoplight.blu.toys.ble.inter.IBlePeripheralCallback;
import com.stoplight.blu.toys.utils.BlePeripheralHelper;
import java.util.List;
......@@ -36,19 +42,48 @@ public class BluetoothOpenAndClose extends BroadcastReceiver {
break;
case BluetoothAdapter.STATE_ON:
LogUtils.d("手机蓝牙开启");
//
// BleScanRuleConfig scanRuleConfig = new BleScanRuleConfig.Builder()
// .setServiceUuids(serviceUuids)
// //.setDeviceName(true, names)
// //.setDeviceMac(mac)
// .setAutoConnect(false)
// .setScanTimeOut(10000)
// .build();
//BleManager.getInstance().initScanRule(scanRuleConfig);
//myService.startBle();
BlePeripheralHelper mBlePeripheralHelper = BlePeripheralHelper.getInstance(context);
if (mBlePeripheralHelper.isBleEnabled()){
// 设置回调
System.out.println("--------------------startBle");
mBlePeripheralHelper.setBlePeripheralCallback(new IBlePeripheralCallback() {
//连接状态回调
@Override
public void onConnectionStateChange(BluetoothDevice bluetoothDevice, int i, int i1) {
System.out.println(bluetoothDevice);
}
//开启广播成功回调
@Override
public void onStartAbSuccess(AdvertiseSettings advertiseSettings) {
System.out.println(advertiseSettings);
}
//开启广失败的功回调
@Override
public void onStartAbFailure(int i) {
System.out.println(i);
}
//收到BLE数据回调
@Override
public void onReceiveNewBytes(BluetoothDevice bluetoothDevice, int i, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bytes) {
System.out.println(bluetoothDevice);
}
//发送BLE数据回调
@Override
public void onWriteBytesAndStatus(boolean b, byte[] bytes) {
System.out.println(bytes);
}
});
// 初始化广播
mBlePeripheralHelper.initGATTServer();
}
break;
......@@ -58,4 +93,9 @@ public class BluetoothOpenAndClose extends BroadcastReceiver {
}
}
}
public BluetoothOpenAndClose (){
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext {
targetCompatibility = JavaVersion.VERSION_1_8
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
......
......@@ -3,21 +3,29 @@ android {
compileSdkVersion 32
defaultConfig {
minSdkVersion 14
<<<<<<< HEAD
targetSdkVersion 32
=======
targetSdkVersion 28
versionCode 3
versionName "1.3"
>>>>>>> ee610bcfe666c5a8aee5df89f5948dec147a6d1f
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
versionNameSuffix '1.0'
debuggable false
jniDebuggable false
renderscriptDebuggable false
renderscriptOptimLevel 3
signingConfig signingConfigs.debug
}
debug {
versionNameSuffix '1.0'
debuggable true
jniDebuggable false
renderscriptDebuggable true
renderscriptOptimLevel 3
signingConfig signingConfigs.debug
minifyEnabled false
multiDexEnabled true
}
}
lintOptions {
......@@ -60,5 +68,5 @@ artifacts {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
compileOnly 'androidx.recyclerview:recyclerview:1.0.0'
compileOnly 'androidx.recyclerview:recyclerview:1.2.0'
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment