Commit fa78d283 by Jeong Gilmo

#32917 芯温センサー

- 外部機器と接続について改善
parent 6bf700e7
......@@ -18,10 +18,12 @@ import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;
import static android.bluetooth.BluetoothDevice.TRANSPORT_LE;
import static org.chromium.base.ThreadUtils.runOnUiThread;
public class BleManagerUtil {
......@@ -95,12 +97,15 @@ public class BleManagerUtil {
}
if( BluetoothProfile.STATE_DISCONNECTED == newState ) { // 切断完了(接続可能範囲から外れて切断された)
// 接続可能範囲に入ったら自動接続するために、mBluetoothGatt.connect()を呼び出す。
mBluetoothGatt.connect();
// 接続可能範囲に入ったら自動接続することが必要場合、mBluetoothGatt.connect()を呼び出す。
// mBluetoothGatt.connect();
// 切断が発生する場合、Bluetoothと接続を切断する。
disconnect();
runOnUiThread( new Runnable() {
public void run() {
// 切断トーストメッセージを表示する。
listener.onDisConnectionState();
// listener.onDisConnectionState();
}
} );
return;
......@@ -223,9 +228,16 @@ public class BleManagerUtil {
// mBluetoothGattのサービスと接続
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice( mDeviceAddress );
// GATT BLEを利用する時Androidのバージョン「23」をチェックしてGATTと接続する。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mBluetoothGatt = device.connectGatt( context, false, mGattcallback, TRANSPORT_LE);
} else {
mBluetoothGatt = device.connectGatt( context, false, mGattcallback );
}
}
// 切断
public void disconnect() {
if( null == mBluetoothGatt ) {
......
......@@ -396,8 +396,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
// 接続されている機器と切断する。
if( null != bleManagerUtil.mBluetoothGatt )
{
bleManagerUtil.mBluetoothGatt.close();
bleManagerUtil.mBluetoothGatt = null;
bleManagerUtil.mBluetoothGatt.disconnect();
putUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 0);
}
}
......
......@@ -259,8 +259,7 @@ public class PairingSettingActivity extends ABVUIActivity implements AdapterView
// Gattサービスがある場合、切断するためnullにする。
if( null != bleManagerUtil.mBluetoothGatt ) {
bleManagerUtil.mBluetoothGatt.close();
bleManagerUtil.mBluetoothGatt = null;
bleManagerUtil.mBluetoothGatt.disconnect();
putUserPref(AppDefType.UserPrefKey.BLUETOOTH_DEVICE_TEMPERATURE_CONNECTED, 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