android - AltBeacon 看不到 eddystone 设备
问题描述
大家好,我使用 Android API 使用信标已经有一段时间了,我能够检测到我所有的信标,其中一个是在 URL 中设置的 Eddystone,实际上图书馆'com.neovisionaries:nvbluetooth:1.8'
可以识别它。但是当使用 AltBeacon 库时,没有找到任何设备,甚至没有找到我为其设置解析器的 Eddystone
public class MainActivity extends Activity implements BeaconConsumer {
protected static final String TAG = "MonitoringActivity";
private BeaconManager beaconManager;
private static final int PERMISSION_REQUEST_FINE_LOCATION = 1;
private static final int PERMISSION_REQUEST_BACKGROUND_LOCATION = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkLocationPermission();
beaconManager = BeaconManager.getInstanceForApplication(this);
// Detect the main identifier (UID) frame:
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
// Detect the telemetry (TLM) frame:
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout(BeaconParser.EDDYSTONE_TLM_LAYOUT));
// Detect the URL frame:
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT));
beaconManager.bind(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
beaconManager.unbind(this);
}
@Override
public void onBeaconServiceConnect() {
beaconManager.removeAllMonitorNotifiers();
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", null, null, null));
} catch (RemoteException ignored) { }
}
private void checkLocationPermission() {
if (this.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
if (this.checkSelfPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
if (this.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_BACKGROUND_LOCATION)) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("This app needs background location access");
builder.setMessage("Please grant location access so this app can detect beacons in the background.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(dialog ->
requestPermissions(new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION},
PERMISSION_REQUEST_BACKGROUND_LOCATION));
builder.show();
} else {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Functionality limited");
builder.setMessage("Since background location access has not been granted, this app will not be able to discover beacons in the background. Please go to Settings -> Applications -> Permissions and grant background location access to this app.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(dialog -> {});
builder.show();
}
}
} else {
if (!this.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION},
PERMISSION_REQUEST_FINE_LOCATION);
} else {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Functionality limited");
builder.setMessage("Since location access has not been granted, this app will not be able to discover beacons. Please go to Settings -> Applications -> Permissions and grant location access to this app.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(dialog -> {});
builder.show();
}
}
}
代码直接从示例代码中复制而来,我添加的唯一新checklocation
功能是我添加的功能,用于解决仅使用清单时手机没有正确授予我权限的问题(正如我在使用原始文件时发现的那样蜜蜂)
也作为额外信息:我的构建文件设置如下:minSdkVersion 24 targetSdkVersion 30
知道为什么我的代码不起作用吗?
谢谢
编辑来自https://altbeacon.github.io/android-beacon-library/detection-trouble.html的额外信息
- NRF 发现信标为 Eddystone V3.0
- 该
Checkbluetooth
函数正是这样做的,我确认它正确地获得了权限(基于我使用 android API 构建的并行应用程序) - 是(见上文)
- 是的(见上面的代码)
- 是的
- 是的
- 不是三星,是 BLU Grand M2
解决方案
显然代码有效,关闭手机然后重新打开它不知道为什么会这样
推荐阅读
- ruby-on-rails - 如何为 Ruby 哈希实现分页
- jquery - jQuery:获取对象内对象的成员数
- ios - Firebase iOS com.apple.avfoundation.playerlayer.configuration 崩溃?
- sql-server - 用户登录失败(Microsoft SQL Server,错误:4064)
- apache-spark - 如何使 pyspark DAG 并行运行
- java - SQL 语法异常 - 无效字符,但查询工作正常
- ios - 具有单个 pickerView 的多个 TableViewCell
- javascript - 使用 css/javascript 旋转图像
- android - 具有多个参数的 BindingAdapter 不起作用
- google-bigquery - 如何使用服务使用启用 Bigquery API?