質問編集履歴

9

2019/06/10 23:13

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
@@ -36,264 +36,4 @@
36
36
 
37
37
  W/ModelSpecificDistanceCalculator: Cannot find match for this device. Using default
38
38
 
39
- Cannot find match for this device. Using default
39
+ Cannot find match for this device.
40
-
41
-
42
-
43
- ### ソースコード
44
-
45
-
46
-
47
- import android.app.Activity;
48
-
49
- import android.bluetooth.BluetoothAdapter;
50
-
51
- import android.bluetooth.BluetoothManager;
52
-
53
- import android.content.Context;
54
-
55
- import android.content.Intent;
56
-
57
- import android.content.pm.PackageManager;
58
-
59
- import android.os.Build;
60
-
61
- import android.os.Bundle;
62
-
63
- import android.os.RemoteException;
64
-
65
- import android.support.v7.app.AppCompatActivity;
66
-
67
- import android.util.Log;
68
-
69
- import android.widget.TextView;
70
-
71
- // AltBeacon関連
72
-
73
- import org.altbeacon.beacon.Beacon;
74
-
75
- import org.altbeacon.beacon.BeaconConsumer;
76
-
77
- import org.altbeacon.beacon.BeaconParser;
78
-
79
- import org.altbeacon.beacon.BeaconManager;
80
-
81
- import org.altbeacon.beacon.Identifier;
82
-
83
- import org.altbeacon.beacon.MonitorNotifier;
84
-
85
- import org.altbeacon.beacon.Region;
86
-
87
-
88
-
89
- public class BeaconApp extends AppCompatActivity implements BeaconConsumer {
90
-
91
-   //bluetooth
92
-
93
- static final int PERMISSION_REQUEST_COARSE_LOCATION = 1;
94
-
95
-
96
-
97
-
98
-
99
- TextView statusMessage;
100
-
101
- TextView machine;
102
-
103
- TextView distance;
104
-
105
-
106
-
107
- BeaconManager beaconManager;
108
-
109
- static String TAG = "AltBeacon Sample";
110
-
111
-
112
-
113
- // iBeaconのデータを認識するためのParserフォーマット
114
-
115
- static String IBEACON_FORMAT = "m:2-3=0215,i:4-19,i:4-19,i:20-21,i:22-23,p:24-24";
116
-
117
-
118
-
119
- @Override
120
-
121
- protected void onCreate(Bundle savedInstanceState) {
122
-
123
- super.onCreate(savedInstanceState);
124
-
125
- setContentView(R.layout.activity_beacon_app);
126
-
127
-
128
-
129
-
130
-
131
- //beaconを使うための設定
132
-
133
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
134
-
135
- if (this.checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
136
-
137
- requestPermissions(new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION},PERMISSION_REQUEST_COARSE_LOCATION);
138
-
139
- }
140
-
141
- }
142
-
143
-
144
-
145
- beaconManager = BeaconManager.getInstanceForApplication(this);
146
-
147
-
148
-
149
- // BeaconParseを設定
150
-
151
- beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(IBEACON_FORMAT));
152
-
153
-
154
-
155
- statusMessage = (TextView)findViewById(R.id.status_message);
156
-
157
- machine = (TextView)findViewById(R.id.machine);
158
-
159
- distance = (TextView)findViewById(R.id.distance);
160
-
161
-
162
-
163
- statusMessage.setText(R.string.out_region);
164
-
165
-
166
-
167
- }
168
-
169
-
170
-
171
- @Override
172
-
173
- public void onBeaconServiceConnect() {
174
-
175
- // UUIDの作成
176
-
177
- Identifier identifier = Identifier.parse("48534442-4c45-4144-80c0-1800ffffffff");
178
-
179
- Identifier major = Identifier.parse("1");
180
-
181
- Identifier minor = Identifier.parse("1");
182
-
183
-
184
-
185
- final Region mRegion = new Region("machine1", identifier, major, minor);
186
-
187
- machine.setText(R.string.machine1);
188
-
189
-
190
-
191
- statusMessage.setText(R.string.in_region);
192
-
193
-
194
-
195
- try {
196
-
197
- // レンジングの開始
198
-
199
- // beaconManager.startRangingBeaconsInRegion(mRegion);
200
-
201
- beaconManager.startMonitoringBeaconsInRegion(mRegion);
202
-
203
-
204
-
205
- } catch (RemoteException e) {
206
-
207
- e.printStackTrace();
208
-
209
- }
210
-
211
- // BeaconManagerクラスのモニタリング通知受取り処理
212
-
213
- beaconManager.addMonitorNotifier(new MonitorNotifier() {
214
-
215
-
216
-
217
-
218
-
219
- @Override
220
-
221
- public void didEnterRegion(Region region) {
222
-
223
- // 領域進入時に実行
224
-
225
- Log.d(TAG, "didEnterRegion");
226
-
227
- statusMessage.setText(R.string.enter_region);
228
-
229
-
230
-
231
- }
232
-
233
-
234
-
235
- @Override
236
-
237
- public void didExitRegion(Region region) {
238
-
239
- // 領域退出時に実行
240
-
241
- Log.d(TAG, "didExitRegion");
242
-
243
- statusMessage.setText(R.string.exit_region);
244
-
245
- }
246
-
247
-
248
-
249
- @Override
250
-
251
- public void didDetermineStateForRegion(int i, Region region) {
252
-
253
- // 領域への侵入/退出のステータスが変化したときに実行
254
-
255
- Log.d(TAG, "change");
256
-
257
- statusMessage.setText(R.string.change_region);
258
-
259
- }
260
-
261
- });
262
-
263
- }
264
-
265
- @Override
266
-
267
- public void onPause() {
268
-
269
- super.onPause();
270
-
271
- this. beaconManager.unbind(this);
272
-
273
- }
274
-
275
-
276
-
277
- @Override
278
-
279
- public void onResume() {
280
-
281
- super.onResume();
282
-
283
- this. beaconManager.bind(this);
284
-
285
-
286
-
287
- }
288
-
289
-
290
-
291
- }
292
-
293
-
294
-
295
- ### 補足情報(FW/ツールのバージョンなど)
296
-
297
-
298
-
299
- android5.0を使用しています。

8

2019/06/10 23:13

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
@@ -94,14 +94,6 @@
94
94
 
95
95
 
96
96
 
97
- // Bluetooth機能の有効化要求時の識別コード
98
-
99
- private static final int REQUEST_ENABLEBLUETOOTH = 1;
100
-
101
- // メンバー変数  BluetoothAdapter : Bluetooth処理で必要
102
-
103
- private BluetoothAdapter mBluetoothAdapter;
104
-
105
97
 
106
98
 
107
99
  TextView statusMessage;
@@ -132,118 +124,90 @@
132
124
 
133
125
  setContentView(R.layout.activity_beacon_app);
134
126
 
127
+
128
+
129
+
130
+
135
- // Android端末がBLEサポートしてるか確認
131
+ //beaconを使うため設定
132
+
136
-
133
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
134
+
137
- if( !getPackageManager().hasSystemFeature( PackageManager.FEATURE_BLUETOOTH_LE ) ) {
135
+ if (this.checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
138
-
136
+
139
- Log.d(TAG, "ble_is_not_supported");
137
+ requestPermissions(new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION},PERMISSION_REQUEST_COARSE_LOCATION);
140
-
141
- finish(); // アプリ終了宣言
138
+
142
-
143
- return;
139
+ }
144
140
 
145
141
  }
146
142
 
147
143
 
148
144
 
149
- final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
150
-
151
- mBluetoothAdapter = bluetoothManager.getAdapter();
145
+ beaconManager = BeaconManager.getInstanceForApplication(this);
146
+
147
+
148
+
152
-
149
+ // BeaconParseを設定
150
+
153
- if( null == mBluetoothAdapter ) { // Android端末がBluetoothをサポートしていない
151
+ beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(IBEACON_FORMAT));
152
+
153
+
154
+
154
-
155
+ statusMessage = (TextView)findViewById(R.id.status_message);
156
+
157
+ machine = (TextView)findViewById(R.id.machine);
158
+
159
+ distance = (TextView)findViewById(R.id.distance);
160
+
161
+
162
+
155
- Log.d(TAG, "ble_is_not_supported");
163
+ statusMessage.setText(R.string.out_region);
164
+
165
+
166
+
156
-
167
+ }
168
+
169
+
170
+
171
+ @Override
172
+
173
+ public void onBeaconServiceConnect() {
174
+
157
- finish(); // アプリ終了宣言
175
+ // UUIDの作成
176
+
158
-
177
+ Identifier identifier = Identifier.parse("48534442-4c45-4144-80c0-1800ffffffff");
178
+
179
+ Identifier major = Identifier.parse("1");
180
+
181
+ Identifier minor = Identifier.parse("1");
182
+
183
+
184
+
185
+ final Region mRegion = new Region("machine1", identifier, major, minor);
186
+
187
+ machine.setText(R.string.machine1);
188
+
189
+
190
+
191
+ statusMessage.setText(R.string.in_region);
192
+
193
+
194
+
159
- return;
195
+ try {
196
+
197
+ // レンジングの開始
198
+
199
+ // beaconManager.startRangingBeaconsInRegion(mRegion);
200
+
201
+ beaconManager.startMonitoringBeaconsInRegion(mRegion);
202
+
203
+
204
+
205
+ } catch (RemoteException e) {
206
+
207
+ e.printStackTrace();
160
208
 
161
209
  }
162
210
 
163
-
164
-
165
- //beaconを使うための設定
166
-
167
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
168
-
169
- if (this.checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
170
-
171
- requestPermissions(new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION},PERMISSION_REQUEST_COARSE_LOCATION);
172
-
173
- }
174
-
175
- }
176
-
177
-
178
-
179
- beaconManager = BeaconManager.getInstanceForApplication(this);
180
-
181
-
182
-
183
- // BeaconParseを設定
184
-
185
- beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(IBEACON_FORMAT));
186
-
187
- onResume();
188
-
189
-
190
-
191
- statusMessage = (TextView)findViewById(R.id.status_message);
192
-
193
- machine = (TextView)findViewById(R.id.machine);
194
-
195
- distance = (TextView)findViewById(R.id.distance);
196
-
197
-
198
-
199
- statusMessage.setText(R.string.out_region);
200
-
201
-
202
-
203
- }
204
-
205
-
206
-
207
- @Override
208
-
209
- public void onBeaconServiceConnect() {
210
-
211
- // UUIDの作成
212
-
213
- Identifier identifier = Identifier.parse("48534442-4c45-4144-80c0-1800ffffffff");
214
-
215
- Identifier major = Identifier.parse("1");
216
-
217
- Identifier minor = Identifier.parse("1");
218
-
219
-
220
-
221
- final Region mRegion = new Region("machine1", identifier, major, minor);
222
-
223
- machine.setText(R.string.machine1);
224
-
225
-
226
-
227
- statusMessage.setText(R.string.in_region);
228
-
229
-
230
-
231
- try {
232
-
233
- // レンジングの開始
234
-
235
- // beaconManager.startRangingBeaconsInRegion(mRegion);
236
-
237
- beaconManager.startMonitoringBeaconsInRegion(mRegion);
238
-
239
-
240
-
241
- } catch (RemoteException e) {
242
-
243
- e.printStackTrace();
244
-
245
- }
246
-
247
211
  // BeaconManagerクラスのモニタリング通知受取り処理
248
212
 
249
213
  beaconManager.addMonitorNotifier(new MonitorNotifier() {
@@ -304,39 +268,7 @@
304
268
 
305
269
  super.onPause();
306
270
 
307
- this.beaconManager.unbind(this);
271
+ this. beaconManager.unbind(this);
308
-
309
-
310
-
311
- // Android端末のBluetooth機能の有効化要求
312
-
313
- requestBluetoothFeature();
314
-
315
-
316
-
317
- }
318
-
319
-
320
-
321
- // Android端末のBluetooth機能の有効化要求
322
-
323
- private void requestBluetoothFeature()
324
-
325
- {
326
-
327
- if( mBluetoothAdapter.isEnabled() )
328
-
329
- {
330
-
331
- return;
332
-
333
- }
334
-
335
- // デバイスのBluetooth機能が有効になっていないときは、有効化要求(ダイアログ表示)
336
-
337
- Intent enableBtIntent = new Intent( BluetoothAdapter.ACTION_REQUEST_ENABLE );
338
-
339
- startActivityForResult( enableBtIntent, REQUEST_ENABLEBLUETOOTH );
340
272
 
341
273
  }
342
274
 
@@ -348,45 +280,9 @@
348
280
 
349
281
  super.onResume();
350
282
 
351
- this.beaconManager.bind(this);
283
+ this. beaconManager.bind(this);
352
-
353
- }
284
+
354
-
355
-
356
-
357
- // 機能の有効化ダイアログの操作結果
285
+
358
-
359
- @Override
360
-
361
- protected void onActivityResult( int requestCode, int resultCode, Intent data )
362
-
363
- {
364
-
365
- switch( requestCode )
366
-
367
- {
368
-
369
- case REQUEST_ENABLEBLUETOOTH: // Bluetooth有効化要求
370
-
371
- if( Activity.RESULT_CANCELED == resultCode )
372
-
373
- { // 有効にされなかった
374
-
375
- // Toast.makeText( this, R.string.bluetooth_is_not_working, Toast.LENGTH_SHORT ).show();
376
-
377
- Log.d(TAG, "bluetooth_is_not_working");
378
-
379
- finish(); // アプリ終了宣言
380
-
381
- return;
382
-
383
- }
384
-
385
- break;
386
-
387
- }
388
-
389
- super.onActivityResult( requestCode, resultCode, data );
390
286
 
391
287
  }
392
288
 

7

2018/09/29 05:14

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
File without changes

6

2018/09/27 13:06

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  android studio初心者です。
6
6
 
7
- android studioで作成したアプリでbeaconの出入りがうまく反応しません。
7
+ android studioで作成したアプリでbeaconの出入りの検出がうまくいきません。
8
8
 
9
9
  ビルドや実行時にはエラーは出ませんがアプリ起動後にうまく反応せず画面の表示でもLogでも反応しません。
10
10
 

5

2018/09/27 13:04

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- android studio初心者なため優しく教えていただけるとうれしいです。
5
+ android studio初心者です。
6
6
 
7
7
  android studioで作成したアプリでbeaconの出入りがうまく反応しません。
8
8
 

4

2018/09/27 13:04

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- __b__### 前提・実現したいこと
1
+ ### 前提・実現したいこと
2
2
 
3
3
 
4
4
 

3

2018/09/27 10:39

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
File without changes

2

2018/09/27 10:38

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- ### 前提・実現したいこと
1
+ __b__### 前提・実現したいこと
2
2
 
3
3
 
4
4
 

1

2018/09/27 10:37

投稿

poohrk
poohrk

スコア12

test CHANGED
File without changes
test CHANGED
File without changes