Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abook_check
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abook_android
abook_check
Commits
de536617
Commit
de536617
authored
Jun 29, 2022
by
onuma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
設定時に、アルコールチェッカーを端末とペア設定するように修正
parent
97554d16
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
0 deletions
+83
-0
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/activity/BlePairingSettingActivity.java
+83
-0
No files found.
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/activity/BlePairingSettingActivity.java
View file @
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"
);
}
}
};
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment