Skip to content

Commit

Permalink
fix bluetooth connection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
teamclouday committed Apr 18, 2020
1 parent 165278f commit 62feeb6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
13 changes: 9 additions & 4 deletions Android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.example.androidsteering"
minSdkVersion 19
targetSdkVersion 29
versionCode 2
versionName "2.0"
versionCode 3
versionName "3.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
8 changes: 4 additions & 4 deletions Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidsteering"
android:versionCode="2"
android:versionCodeMajor="2"
android:versionName="Version 2.0">
package="com.example.androidsteering">
<!-- android:versionCode="2"-->
<!-- android:versionCodeMajor="2"-->
<!-- android:versionName="Version 2.0"-->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import androidx.appcompat.app.AppCompatActivity;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
Expand Down Expand Up @@ -375,11 +376,11 @@ else if(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action))
{
disconnect();
}
else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))
{
updateStatus(BluetoothStatus.NONE);
findTargetDevice();
}
// else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))
// {
// updateStatus(BluetoothStatus.NONE);
// findTargetDevice();
// }
}
};

Expand Down Expand Up @@ -412,7 +413,7 @@ public void updatePotential()
{
for(BluetoothDevice device : pairedDevices)
{
if(device.getBluetoothClass().getMajorDeviceClass() == 256)
if(device.getBluetoothClass().getMajorDeviceClass() == BluetoothClass.Device.Major.COMPUTER)
{
potentialDevices.add(device);
}
Expand All @@ -428,7 +429,8 @@ public void updatePotential()
// filter.addAction(BluetoothDevice.ACTION_FOUND);
registerReceiver(myReceiver, filter);
updateStatus(BluetoothStatus.SEARCHING);
myAdapter.startDiscovery();
findTargetDevice();
// myAdapter.startDiscovery();
}
else
{
Expand All @@ -449,6 +451,7 @@ private void findTargetDevice()
if(testConnection(d))
{
targetDevice = d;
updateStatus(BluetoothStatus.NONE);
break;
}
}
Expand Down

0 comments on commit 62feeb6

Please sign in to comment.