1
我一直在嘗試掃描信標,但我無法進行掃描。我嘗試了所有的StackOverflow問題,但我還沒有找到答案。無法掃描信標
下面是我的代碼:
MAINACTIVITY:
public class MainActivity extends AppCompatActivity implements BeaconConsumer {
protected static final String TAG = "MonitoringActivity";
private BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
beaconManager.bind(this);}
@Override
public void onBeaconServiceConnect() {
beaconManager.addMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
Log.i(TAG, "I just saw an beacon for the first time!");
}
@Override
public void didExitRegion(Region region) {
Log.i(TAG, "I no longer see an beacon");
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.i(TAG, "I have just switched from seeing/not seeing beacons: "+state);
}
});
try {
beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", Identifier.parse(null, null, null));
} catch (RemoteException e) { }
}
清單
gradle.properties
manifestmerger.enabled=true
logcat的
06-19 20:03:37.403 7459-7459/com.example.beaconscanner D/BeaconParser: Parsing beacon layout: m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25
06-19 20:03:37.796 7459-7459/com.example.beaconscanner I/MonitoringActivity: I have just switched from seeing/not seeing beacons: 0
06-19 20:03:37.933 7459-7729/com.example.beaconscanner D/BluetoothAdapter: STATE_ON
06-19 20:03:37.938 7459-7471/com.example.beaconscanner D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=12
06-19 20:03:39.038 7459-7729/com.example.beaconscanner D/BluetoothAdapter: STATE_ON
06-19 20:03:39.040 7459-7729/com.example.beaconscanner D/BluetoothAdapter: STATE_ON
06-19 20:03:39.044 7459-7470/com.example.beaconscanner D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=12
我已根據Android SDK中的藍牙添加權限位置和大於23
它的工作原理是將Beaconlayout更改爲m:2-3 = 0215,i:4-19,i:20-21,i:22-23,p:24-24' – Burhan