用于EddyStone信标的Android信标库

问题描述 投票:0回答:1

我是使用Android扫描信标的新手。我正在使用上述图书馆,这很容易理解。参考应用程序可以工作并检测我的Eddystone信标。根据示例代码,我编写了一个简单的应用程序来检测Eddystone信标。这没用。在logcat上,我收到以下消息;D /蓝牙适配器:STATE_OND / BluetoothLeScanner:找不到回调包装器

这是我的代码,任何人都可以告诉我,我在做什么错。请帮助。

       public class MainActivity extends AppCompatActivity implements BeaconConsumer {
private BeaconManager beaconManager;
Identifier myBeaconNamespaceId;
Identifier myBeaconInstanceId;
Region region;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    myBeaconNamespaceId = Identifier.parse("0x334652820242ac130002");
    myBeaconInstanceId = Identifier.parse("0x987654321cba");
    beaconManager = BeaconManager.getInstanceForApplication(this.getApplicationContext());
    beaconManager.getBeaconParsers().clear();
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
   // beaconManager.setDebug(true);

    region = new Region("MyRegion",
            myBeaconNamespaceId, myBeaconInstanceId, null);
    beaconManager.bind(this);

}

@Override
protected void onDestroy() {
    super.onDestroy();
    beaconManager.unbind(this);
}


@Override
public void onBeaconServiceConnect() {
    beaconManager.removeAllRangeNotifiers();
    beaconManager.addRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
            if (beacons.size() > 0) {

                Log.i("INFORMATION", "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away.");
            }
        }
    });

    try {
        beaconManager.startRangingBeaconsInRegion(new Region("MyRegion", myBeaconNamespaceId, myBeaconInstanceId, null));
    } catch (RemoteException e) {
        Toast.makeText(getApplicationContext(), e.getMessage()  ,Toast.LENGTH_LONG).show();
    }
}

private void logToDisplay(final String line) {
    runOnUiThread(new Runnable() {
        public void run() {
            EditText editText = (EditText)MainActivity.this.findViewById(R.id.rangingText);
            editText.append(line+"\n");
        }
    });
}
}
android bluetooth beacon eddystone
1个回答
0
投票

确保通过动态请求获得用户的位置许可:

https://altbeacon.github.io/android-beacon-library/requesting_permission.html

如果不起作用,我在这里还有其他一些故障排除步骤:

https://altbeacon.github.io/android-beacon-library/detection-trouble.html

© www.soinside.com 2019 - 2024. All rights reserved.