应用程序在不同设备上扫描信标时的不同反应
different reaction of application in scanning beacons on different devices
我有一个扫描周围 BLE 信标的应用程序。我已经使用 Altbeacon 库来做到这一点。当我 运行 它在我的 Nexus 6p 上它找到了一些信标,但是当我 运行 它在 galaxy s9 或 Kindle fire HD 8 上它发现的信标数量始终为零。这是我的代码:
override fun onBeaconServiceConnect() {
beaconManager.removeAllRangeNotifiers()
beaconManager.addRangeNotifier(object : RangeNotifier {
override fun didRangeBeaconsInRegion(beacons: Collection<Beacon>, region: Region) {
Log.i("ranging" , "beacons size:" + beacons.size)
for (b in beacons) {
Toast.makeText(getApplicationContext(),b.id1.toString() + " beacon I see is about " + b.rssi + " away.",
Toast.LENGTH_SHORT).show();
}
}
})
try {
beaconManager.startRangingBeaconsInRegion(Region("myRangingUniqueId", Identifier.parse(""), null, null))
} catch (e: RemoteException) {
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val binding : com.example.attendancecheck_v1.databinding.FragmentTeacherScanningBinding = DataBindingUtil.inflate(
inflater, R.layout.fragment_teacher_scanning, container, false)
beaconManager.bind(this)
setHasOptionsMenu(true)
return binding.root
}
顺便说一句,我在我的设备上安装了一个信标模拟器,它可以扫描信标,但在我的代码中,这些设备上的输出为零。
用这个区域检查一下:
beaconManager.startRangingBeaconsInRegion(Region("myRangingUniqueId", null, null, null))
我有一个扫描周围 BLE 信标的应用程序。我已经使用 Altbeacon 库来做到这一点。当我 运行 它在我的 Nexus 6p 上它找到了一些信标,但是当我 运行 它在 galaxy s9 或 Kindle fire HD 8 上它发现的信标数量始终为零。这是我的代码:
override fun onBeaconServiceConnect() {
beaconManager.removeAllRangeNotifiers()
beaconManager.addRangeNotifier(object : RangeNotifier {
override fun didRangeBeaconsInRegion(beacons: Collection<Beacon>, region: Region) {
Log.i("ranging" , "beacons size:" + beacons.size)
for (b in beacons) {
Toast.makeText(getApplicationContext(),b.id1.toString() + " beacon I see is about " + b.rssi + " away.",
Toast.LENGTH_SHORT).show();
}
}
})
try {
beaconManager.startRangingBeaconsInRegion(Region("myRangingUniqueId", Identifier.parse(""), null, null))
} catch (e: RemoteException) {
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val binding : com.example.attendancecheck_v1.databinding.FragmentTeacherScanningBinding = DataBindingUtil.inflate(
inflater, R.layout.fragment_teacher_scanning, container, false)
beaconManager.bind(this)
setHasOptionsMenu(true)
return binding.root
}
顺便说一句,我在我的设备上安装了一个信标模拟器,它可以扫描信标,但在我的代码中,这些设备上的输出为零。
用这个区域检查一下:
beaconManager.startRangingBeaconsInRegion(Region("myRangingUniqueId", null, null, null))