Commit 6f2dea66 by onuma

Merge branch 'features/1.4.300_qa' into features/1.4.300

parents 78b23091 de536617
......@@ -3,10 +3,17 @@ package jp.agentec.abook.abv.ui.home.activity;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
......@@ -25,8 +32,10 @@ import java.util.List;
import jp.agentec.abook.abv.bl.common.Constant;
import jp.agentec.abook.abv.bl.common.Constant.DeviceType;
import jp.agentec.abook.abv.bl.common.constant.ABookKeys;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.dto.BluetoothPairingDeviceInfoDto;
import jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil;
import jp.agentec.abook.abv.cl.util.BleManagerUtil;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity;
......@@ -36,6 +45,8 @@ import jp.agentec.abook.abv.ui.home.adapter.common.SectionHeaderData;
import jp.agentec.abook.abv.ui.home.helper.ABookPermissionHelper;
import jp.agentec.adf.util.CollectionUtil;
import static android.bluetooth.BluetoothDevice.TRANSPORT_LE;
public class BlePairingSettingActivity extends ABVUIActivity {
private static final String TAG = "BlePairingSettingActivity";
......@@ -97,6 +108,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
Logger.i(TAG, "onCreate");
......@@ -153,6 +165,8 @@ public class BlePairingSettingActivity extends ABVUIActivity {
if (!bleListRowData.isSaved) {
localSaveDeviceInfo(bleListRowData);
}
// 端末とペアリングしておく
PairingDevice(bleListRowData.deviceAddress);
}
});
......@@ -414,4 +428,73 @@ public class BlePairingSettingActivity extends ABVUIActivity {
startActivityForResult( enableBtIntent, REQUEST_ENABLEBLUETOOTH );
return false;
}
////////////////////////////////////////////////////////////////////////
private BluetoothGatt bluetoothGatt = null;
private BluetoothAdapter bluetoothAdapter = null;
@Override
protected void onDestroy() {
super.onDestroy();
//unregisterReceiver(PairingRequest);
if(bluetoothGatt != null) {
bluetoothGatt.close();
bluetoothGatt = null;
}
}
BroadcastReceiver PairingRequest = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
Logger.d(TAG,"PEAR");
}
}
};
private void PairingDevice(String deviceAddress) {
BluetoothManager bleMgr = (BluetoothManager) this.getSystemService( Context.BLUETOOTH_SERVICE );
if (bleMgr != null) {
bluetoothAdapter = bleMgr.getAdapter();
if (bluetoothAdapter == null) {
return;
}
}
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(deviceAddress);
//bluetoothGatt = device.connectGatt(this, false, gattcallback, TRANSPORT_LE);
device.createBond();
//IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
//registerReceiver(PairingRequest, filter);
}
private final BluetoothGattCallback gattcallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
if (newState == BluetoothProfile.STATE_CONNECTED) {
//
Logger.d(TAG, "STATE_CONNECTED");
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
//
Logger.d(TAG, "STATE_DISCONNECTED");
if (bluetoothGatt != null) {
bluetoothGatt.close();
bluetoothGatt = null;
}
}
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
super.onServicesDiscovered(gatt, status);
if (status == BluetoothGatt.GATT_SUCCESS) {
bluetoothGatt = gatt;
Logger.d(TAG,"BluetoothGatt.GATT_SUCCESS");
}
}
};
}
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