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
4d58bf12
Commit
4d58bf12
authored
Jun 30, 2022
by
onuma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
133エラー発生時、10回までリトライするように修正した
parent
6f2dea66
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
5 deletions
+19
-5
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtil.java
+19
-5
No files found.
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtil.java
View file @
4d58bf12
...
...
@@ -40,10 +40,12 @@ public class BleManagerUtil {
// メンバー変数
public
BluetoothAdapter
mBluetoothAdapter
;
// BluetoothAdapter : Bluetooth処理で必要
private
String
mDeviceAddress
=
""
;
// デバイスアドレス
public
BluetoothGatt
mBluetoothGatt
=
null
;
// Gattサービスの検索、キャラスタリスティックの読み書き
private
int
mBleConnectDeviceType
;
private
String
mDeviceAddress
=
""
;
// デバイスアドレス
private
BluetoothDevice
mDevice
;
private
int
retryCount
=
0
;
private
static
final
int
RETRY_MAX
=
10
;
public
BleManagerUtil
(
Context
context
,
BleManagerUtilListener
listener
)
{
mContext
=
context
;
...
...
@@ -59,11 +61,23 @@ public class BleManagerUtil {
Logger
.
i
(
"onConnectionStateChange status = "
+
status
+
" newState = "
+
newState
);
if
(
newState
==
BluetoothProfile
.
STATE_CONNECTED
)
{
gatt
.
discoverServices
();
return
;
}
// デバイスと接続されていない場合のメッセージコード:133, 62
// デバイスと離れて応答がなく、タイムアウトになる場合:8
// デバイスと接続が切れた場合のメッセージコード:19
if
(
status
==
133
||
status
==
62
||
status
==
8
||
status
==
19
)
{
// 接続失敗
if
(
status
==
133
)
{
if
(
retryCount
<
RETRY_MAX
)
{
retryCount
++;
new
Handler
(
Looper
.
getMainLooper
()).
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
mBluetoothGatt
=
mDevice
.
connectGatt
(
mContext
,
false
,
mGattcallback
,
TRANSPORT_LE
);
}
},
1500
);
}
}
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
@@ -257,8 +271,8 @@ public class BleManagerUtil {
}
// mBluetoothGattのサービスと接続
BluetoothDevice
d
evice
=
mBluetoothAdapter
.
getRemoteDevice
(
deviceAddress
);
if
(
d
evice
.
getName
()
==
null
)
{
mD
evice
=
mBluetoothAdapter
.
getRemoteDevice
(
deviceAddress
);
if
(
mD
evice
.
getName
()
==
null
)
{
// deviceの名称がない場合、接続エラーになるため、再スキャンすることで検知したらgetRemoteDeviceメソッドに名称がセットされる
mBluetoothAdapter
.
getBluetoothLeScanner
().
startScan
(
mScanCallback
);
// スキャン開始(一定時間後にスキャン停止する)
...
...
@@ -271,7 +285,7 @@ public class BleManagerUtil {
}
},
20000
);
}
else
{
bleGattConnect
(
d
evice
);
bleGattConnect
(
mD
evice
);
}
}
...
...
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