如何解决AltBeacon没有看到涡流仪
大家好,我已经使用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));
} 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
函数,用于解决仅在使用清单(例如我是在使用原始API时发现的)
还有一些其他信息:我的构建文件设置如下:minSdkVersion 24 targetSdkVersion 30
知道我的代码为什么不起作用吗?
谢谢
编辑来自的其他信息 https://altbeacon.github.io/android-beacon-library/detection-trouble.html
- NRF找到了灯塔作为Eddystone V3.0
-
Checkbluetooth
函数确实做到了这一点,并且我确认它可以正确获得特权(基于我使用android API构建的并行应用程序) - 是(见上文)
- 是(请参见上面的代码)
- 是
- 是
- 不是三星,而是BLU Grand M2
解决方法
显然,该代码可以正常工作,关闭手机后再重新打开就可以了,虽然不知道为什么会这样
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。