gpt4 book ai didi

android - 找不到带有 altbeacon 库的信标

转载 作者:行者123 更新时间:2023-11-30 00:34:40 26 4
gpt4 key购买 nike

Ì 我正在尝试连接我的 Android 应用程序中的信标。但我似乎找不到我的信标。我正在使用 Ibeacons。我正在使用 AltBeacon 库。 onBeaconServiceConnect 开始,然后是 didDetermineStateForRegion。但是 didEnterReion 永远不会被调用。这是我的代码:

public class ListScenarios extends AppCompatActivity implements BeaconConsumer, MonitorNotifier {

private static final String TAG = "ListScenarios";

private ListView listView;
public String persoonID;
public String adresID;

public Array beaconArray;
//private ArrayList<IBeacon> arrBeacons = new ArrayList<>();

private BeaconManager mBeaconManager;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_scenarios);

// Setup beaconmanager
mBeaconManager = BeaconManager.getInstanceForApplication(this.getApplicationContext());
// Detect iBeacon
mBeaconManager.getBeaconParsers().add(new BeaconParser()
.setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
mBeaconManager.bind(this);



//listview
listView = (ListView) findViewById(R.id.list_scenario);

//send request to load list
getScenarios();
getBeacons();



}


// MARK: - Bluetooth


@Override
public void onBeaconServiceConnect() {
System.out.println("We are in onBeaconServiceConnect");
// Set the two identifiers below to null to detect any beacon regardless of identifiers
Identifier myBeaconNamespaceId = null;
Identifier myBeaconInstanceId = null;
Region region = new Region("my-beacon-region", myBeaconNamespaceId, myBeaconInstanceId, null);
mBeaconManager.addMonitorNotifier(this);
try {
mBeaconManager.startMonitoringBeaconsInRegion(region);
} catch (RemoteException e) {
e.printStackTrace();
}
}

public void didEnterRegion(Region region) {
System.out.println("We are in didEnterRegion");
Log.d(TAG, "I detected a beacon in the region with namespace id " + region.getId1() +
" and instance id: " + region.getId2());
}

public void didExitRegion(Region region) {
System.out.println("We are in didExitRegion");
}

public void didDetermineStateForRegion(int state, Region region) {
System.out.println("We are in didDetermineStateForRegion");
}

@Override
public void onPause() {
super.onPause();
mBeaconManager.unbind(this);
}

最佳答案

要检查两件事:

  1. 确保您使用的是正确的 BeaconParser 表达式。问题中显示的表达式适用于 AltBeacon:"m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25- 25。如果您尝试检测 iBeacon,则需要使用不同的表达式。此站点有一个方便的引用:https://beaconlayout.wordpress.com/

  2. 如果您在 Android 6+ 上运行您的应用程序并以 SDK 23 或更高版本为目标,则您需要为您的应用程序动态请求位置权限。如果你不这样做,你将得不到任何检测,你会在日志中看到:04-22 22:35:20.152 5158 5254 E BluetoothUtils: Permission denial: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan结果 您可以在此处阅读如何执行此操作:http://altbeacon.github.io/android-beacon-library/requesting_permission.html

关于android - 找不到带有 altbeacon 库的信标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43623151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com