質問編集履歴
4
運営による復元
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,13 +1,145 @@
|
|
1
1
|
### 実現したいこと
|
2
|
-
iBeaconの情報をLogcatに表示されるようにしたい。
|
2
|
+
検知したiBeaconの情報をLogcatに表示されるようにしたい。
|
3
3
|
|
4
4
|
### 発生している問題・分からないこと
|
5
|
+
検知した際にLogcatにUUIDやmajor, minorなどを表示できるはずが、表示されない。
|
5
6
|
|
6
7
|
|
7
8
|
|
8
9
|
### 該当のソースコード
|
9
10
|
|
11
|
+
```MainActivity.java
|
12
|
+
package com.example.myapplication;
|
10
13
|
|
14
|
+
import android.os.Bundle;
|
15
|
+
import android.os.RemoteException;
|
16
|
+
import android.util.Log;
|
17
|
+
|
18
|
+
import androidx.appcompat.app.AppCompatActivity;
|
19
|
+
|
20
|
+
import org.altbeacon.beacon.Beacon;
|
21
|
+
import org.altbeacon.beacon.BeaconConsumer;
|
22
|
+
import org.altbeacon.beacon.BeaconManager;
|
23
|
+
import org.altbeacon.beacon.BeaconParser;
|
24
|
+
import org.altbeacon.beacon.MonitorNotifier;
|
25
|
+
import org.altbeacon.beacon.RangeNotifier;
|
26
|
+
import org.altbeacon.beacon.Region;
|
27
|
+
|
28
|
+
import java.util.Collection;
|
29
|
+
|
30
|
+
public class MainActivity extends AppCompatActivity implements BeaconConsumer {
|
31
|
+
|
32
|
+
private static final String IBEACON_FORMAT = "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24";
|
33
|
+
|
34
|
+
private BeaconManager beaconManager;
|
35
|
+
|
36
|
+
@Override
|
37
|
+
protected void onCreate(Bundle savedInstanceState) {
|
38
|
+
super.onCreate(savedInstanceState);
|
39
|
+
setContentView(R.layout.activity_main);
|
40
|
+
|
41
|
+
beaconManager = BeaconManager.getInstanceForApplication(this);
|
42
|
+
|
43
|
+
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(IBEACON_FORMAT));
|
44
|
+
|
45
|
+
beaconManager.addRangeNotifier(new RangeNotifier() {
|
46
|
+
@Override
|
47
|
+
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
|
48
|
+
for (Beacon beacon : beacons) {
|
49
|
+
Log.d("MyActivity", "UUID:" + beacon.getId1() + ", major:"
|
50
|
+
+ beacon.getId2() + ", minor:" + beacon.getId3() + ", RSSI:"
|
51
|
+
+ beacon.getRssi() + ", TxPower:" + beacon.getTxPower()
|
52
|
+
+ ", Distance:" + beacon.getDistance());
|
53
|
+
}
|
54
|
+
try {
|
55
|
+
beaconManager.startRangingBeaconsInRegion(region);
|
56
|
+
} catch (RemoteException e) {
|
57
|
+
e.printStackTrace();
|
58
|
+
}
|
59
|
+
}
|
60
|
+
});
|
61
|
+
|
62
|
+
}
|
63
|
+
|
64
|
+
@Override
|
65
|
+
protected void onResume() {
|
66
|
+
super.onResume();
|
67
|
+
beaconManager.bind(this);
|
68
|
+
}
|
69
|
+
|
70
|
+
@Override
|
71
|
+
protected void onPause() {
|
72
|
+
super.onPause();
|
73
|
+
beaconManager.unbind(this);
|
74
|
+
}
|
75
|
+
|
76
|
+
@Override
|
77
|
+
public void onBeaconServiceConnect() {
|
78
|
+
final Region mRegion = new Region("iBeacon", null, null, null);
|
79
|
+
beaconManager.addMonitorNotifier(new MonitorNotifier() {
|
80
|
+
@Override
|
81
|
+
public void didEnterRegion(Region region) {
|
82
|
+
Log.d("iBeacon", "Enter Region");
|
83
|
+
}
|
84
|
+
|
85
|
+
@Override
|
86
|
+
public void didExitRegion(Region region) {
|
87
|
+
Log.d("iBeacon", "Exit Region");
|
88
|
+
}
|
89
|
+
|
90
|
+
@Override
|
91
|
+
public void didDetermineStateForRegion(int i, Region region) {
|
92
|
+
Log.d("MyActivity", "Determine State" + i);
|
93
|
+
}
|
94
|
+
|
95
|
+
});
|
96
|
+
|
97
|
+
try {
|
98
|
+
beaconManager.startMonitoringBeaconsInRegion(mRegion);
|
99
|
+
} catch (RemoteException e) {
|
100
|
+
e.printStackTrace();
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
}
|
105
|
+
```
|
106
|
+
|
107
|
+
```
|
108
|
+
AndroidManifest.xml
|
109
|
+
<?xml version="1.0" encoding="utf-8"?>
|
110
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
111
|
+
xmlns:tools="http://schemas.android.com/tools">
|
112
|
+
|
113
|
+
<uses-permission android:name="android.permission.BLUETOOTH" />
|
114
|
+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
115
|
+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
116
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
117
|
+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
118
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
119
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
120
|
+
|
121
|
+
<application
|
122
|
+
android:allowBackup="true"
|
123
|
+
android:dataExtractionRules="@xml/data_extraction_rules"
|
124
|
+
android:fullBackupContent="@xml/backup_rules"
|
125
|
+
android:icon="@mipmap/ic_launcher"
|
126
|
+
android:label="@string/app_name"
|
127
|
+
android:roundIcon="@mipmap/ic_launcher_round"
|
128
|
+
android:supportsRtl="true"
|
129
|
+
android:theme="@style/Theme.MyApplication"
|
130
|
+
tools:targetApi="31">
|
131
|
+
<activity
|
132
|
+
android:name=".MainActivity"
|
133
|
+
android:exported="true">
|
134
|
+
<intent-filter>
|
135
|
+
<action android:name="android.intent.action.MAIN" />
|
136
|
+
|
137
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
138
|
+
</intent-filter>
|
139
|
+
</activity>
|
140
|
+
</application>
|
141
|
+
|
142
|
+
</manifest>
|
11
143
|
```
|
12
144
|
|
13
145
|
### 試したこと・調べたこと
|
3
文章の変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Logcatに情報が表示されない
|
test
CHANGED
@@ -1,145 +1,13 @@
|
|
1
1
|
### 実現したいこと
|
2
|
-
|
2
|
+
iBeaconの情報をLogcatに表示されるようにしたい。
|
3
3
|
|
4
4
|
### 発生している問題・分からないこと
|
5
|
-
検知した際にLogcatにUUIDやmajor, minorなどを表示できるはずが、表示されない。
|
6
5
|
|
7
6
|
|
8
7
|
|
9
8
|
### 該当のソースコード
|
10
9
|
|
11
|
-
```MainActivity.java
|
12
|
-
package com.example.myapplication;
|
13
10
|
|
14
|
-
import android.os.Bundle;
|
15
|
-
import android.os.RemoteException;
|
16
|
-
import android.util.Log;
|
17
|
-
|
18
|
-
import androidx.appcompat.app.AppCompatActivity;
|
19
|
-
|
20
|
-
import org.altbeacon.beacon.Beacon;
|
21
|
-
import org.altbeacon.beacon.BeaconConsumer;
|
22
|
-
import org.altbeacon.beacon.BeaconManager;
|
23
|
-
import org.altbeacon.beacon.BeaconParser;
|
24
|
-
import org.altbeacon.beacon.MonitorNotifier;
|
25
|
-
import org.altbeacon.beacon.RangeNotifier;
|
26
|
-
import org.altbeacon.beacon.Region;
|
27
|
-
|
28
|
-
import java.util.Collection;
|
29
|
-
|
30
|
-
public class MainActivity extends AppCompatActivity implements BeaconConsumer {
|
31
|
-
|
32
|
-
private static final String IBEACON_FORMAT = "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24";
|
33
|
-
|
34
|
-
private BeaconManager beaconManager;
|
35
|
-
|
36
|
-
@Override
|
37
|
-
protected void onCreate(Bundle savedInstanceState) {
|
38
|
-
super.onCreate(savedInstanceState);
|
39
|
-
setContentView(R.layout.activity_main);
|
40
|
-
|
41
|
-
beaconManager = BeaconManager.getInstanceForApplication(this);
|
42
|
-
|
43
|
-
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(IBEACON_FORMAT));
|
44
|
-
|
45
|
-
beaconManager.addRangeNotifier(new RangeNotifier() {
|
46
|
-
@Override
|
47
|
-
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
|
48
|
-
for (Beacon beacon : beacons) {
|
49
|
-
Log.d("MyActivity", "UUID:" + beacon.getId1() + ", major:"
|
50
|
-
+ beacon.getId2() + ", minor:" + beacon.getId3() + ", RSSI:"
|
51
|
-
+ beacon.getRssi() + ", TxPower:" + beacon.getTxPower()
|
52
|
-
+ ", Distance:" + beacon.getDistance());
|
53
|
-
}
|
54
|
-
try {
|
55
|
-
beaconManager.startRangingBeaconsInRegion(region);
|
56
|
-
} catch (RemoteException e) {
|
57
|
-
e.printStackTrace();
|
58
|
-
}
|
59
|
-
}
|
60
|
-
});
|
61
|
-
|
62
|
-
}
|
63
|
-
|
64
|
-
@Override
|
65
|
-
protected void onResume() {
|
66
|
-
super.onResume();
|
67
|
-
beaconManager.bind(this);
|
68
|
-
}
|
69
|
-
|
70
|
-
@Override
|
71
|
-
protected void onPause() {
|
72
|
-
super.onPause();
|
73
|
-
beaconManager.unbind(this);
|
74
|
-
}
|
75
|
-
|
76
|
-
@Override
|
77
|
-
public void onBeaconServiceConnect() {
|
78
|
-
final Region mRegion = new Region("iBeacon", null, null, null);
|
79
|
-
beaconManager.addMonitorNotifier(new MonitorNotifier() {
|
80
|
-
@Override
|
81
|
-
public void didEnterRegion(Region region) {
|
82
|
-
Log.d("iBeacon", "Enter Region");
|
83
|
-
}
|
84
|
-
|
85
|
-
@Override
|
86
|
-
public void didExitRegion(Region region) {
|
87
|
-
Log.d("iBeacon", "Exit Region");
|
88
|
-
}
|
89
|
-
|
90
|
-
@Override
|
91
|
-
public void didDetermineStateForRegion(int i, Region region) {
|
92
|
-
Log.d("MyActivity", "Determine State" + i);
|
93
|
-
}
|
94
|
-
|
95
|
-
});
|
96
|
-
|
97
|
-
try {
|
98
|
-
beaconManager.startMonitoringBeaconsInRegion(mRegion);
|
99
|
-
} catch (RemoteException e) {
|
100
|
-
e.printStackTrace();
|
101
|
-
}
|
102
|
-
}
|
103
|
-
|
104
|
-
}
|
105
|
-
```
|
106
|
-
|
107
|
-
```
|
108
|
-
AndroidManifest.xml
|
109
|
-
<?xml version="1.0" encoding="utf-8"?>
|
110
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
111
|
-
xmlns:tools="http://schemas.android.com/tools">
|
112
|
-
|
113
|
-
<uses-permission android:name="android.permission.BLUETOOTH" />
|
114
|
-
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
115
|
-
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
116
|
-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
117
|
-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
118
|
-
<uses-permission android:name="android.permission.INTERNET" />
|
119
|
-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
120
|
-
|
121
|
-
<application
|
122
|
-
android:allowBackup="true"
|
123
|
-
android:dataExtractionRules="@xml/data_extraction_rules"
|
124
|
-
android:fullBackupContent="@xml/backup_rules"
|
125
|
-
android:icon="@mipmap/ic_launcher"
|
126
|
-
android:label="@string/app_name"
|
127
|
-
android:roundIcon="@mipmap/ic_launcher_round"
|
128
|
-
android:supportsRtl="true"
|
129
|
-
android:theme="@style/Theme.MyApplication"
|
130
|
-
tools:targetApi="31">
|
131
|
-
<activity
|
132
|
-
android:name=".MainActivity"
|
133
|
-
android:exported="true">
|
134
|
-
<intent-filter>
|
135
|
-
<action android:name="android.intent.action.MAIN" />
|
136
|
-
|
137
|
-
<category android:name="android.intent.category.LAUNCHER" />
|
138
|
-
</intent-filter>
|
139
|
-
</activity>
|
140
|
-
</application>
|
141
|
-
|
142
|
-
</manifest>
|
143
11
|
```
|
144
12
|
|
145
13
|
### 試したこと・調べたこと
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
### 該当のソースコード
|
10
10
|
|
11
|
-
```M
|
11
|
+
```MainActivity.java
|
12
12
|
package com.example.myapplication;
|
13
13
|
|
14
14
|
import android.os.Bundle;
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -104,6 +104,44 @@
|
|
104
104
|
}
|
105
105
|
```
|
106
106
|
|
107
|
+
```
|
108
|
+
AndroidManifest.xml
|
109
|
+
<?xml version="1.0" encoding="utf-8"?>
|
110
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
111
|
+
xmlns:tools="http://schemas.android.com/tools">
|
112
|
+
|
113
|
+
<uses-permission android:name="android.permission.BLUETOOTH" />
|
114
|
+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
115
|
+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
116
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
117
|
+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
118
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
119
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
120
|
+
|
121
|
+
<application
|
122
|
+
android:allowBackup="true"
|
123
|
+
android:dataExtractionRules="@xml/data_extraction_rules"
|
124
|
+
android:fullBackupContent="@xml/backup_rules"
|
125
|
+
android:icon="@mipmap/ic_launcher"
|
126
|
+
android:label="@string/app_name"
|
127
|
+
android:roundIcon="@mipmap/ic_launcher_round"
|
128
|
+
android:supportsRtl="true"
|
129
|
+
android:theme="@style/Theme.MyApplication"
|
130
|
+
tools:targetApi="31">
|
131
|
+
<activity
|
132
|
+
android:name=".MainActivity"
|
133
|
+
android:exported="true">
|
134
|
+
<intent-filter>
|
135
|
+
<action android:name="android.intent.action.MAIN" />
|
136
|
+
|
137
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
138
|
+
</intent-filter>
|
139
|
+
</activity>
|
140
|
+
</application>
|
141
|
+
|
142
|
+
</manifest>
|
143
|
+
```
|
144
|
+
|
107
145
|
### 試したこと・調べたこと
|
108
146
|
- [x] teratailやGoogle等で検索した
|
109
147
|
- [x] ソースコードを自分なりに変更した
|