Hey guys. I use altbeacon library for getting Ibeacon UUID. I use "beaconManager!!.addRangeNotifier " in onBeaconServiceConnect function. At first I launch my app and it can scan ibeacon correclty. for example 1 beacon is found. then after One time scan it is stopped. then I disconnect my Ibeacon power. it should not be found. but when I click on my Scan button, it still shows previous beacon. I must scan again and finally it is gone. It is something like get cached.
I wanted and did it in fragment, it behaves similar. I write it in Activity again. nothing changed. I upload my code for you.
class RangingActivity : Activity(), BeaconConsumer {
private var beaconManager: BeaconManager? = null
val region = Region("myBeaons", null, null, null)
var isScanFirstTime=true
lateinit var imgScan: ImageView
lateinit var progress: ProgressBar
lateinit var homeRelative2: RelativeLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_ranging)
imgScan=findViewById(R.id.ImgScan)
progress=findViewById(R.id.progressbarInsideHomeFragment)
homeRelative2=findViewById(R.id.HomeRelativeLayout2)
beaconManager = BeaconManager.getInstanceForApplication(this)
beaconManager = BeaconManager.getInstanceForApplication(applicationContext)
beaconManager!!.beaconParsers.add(BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"))
beaconManager!!.foregroundScanPeriod = 10000L
beaconManager!!.foregroundBetweenScanPeriod=2000
beaconManager!!.bind(this)
imgScan.setOnClickListener {
beaconManager!!.startRangingBeaconsInRegion(region)
progress.visibility=View.VISIBLE
homeRelative2.visibility=View.GONE
}
startScan()
}
override fun onDestroy() {
super.onDestroy()
beaconManager!!.unbind(this)
}
override fun onBeaconServiceConnect() {
beaconManager!!.removeAllRangeNotifiers()
beaconManager!!.addRangeNotifier { beacons, region ->
stopScan()
if (beacons.size > 0) {
Log.d("BeaconList", "didRangeBeaconsInRegion called with beacon count: " + beacons.size)
for (beacon in beacons) {
Log.d("BeaconList", "uuid: " + beacon.id1)
}
progress.visibility = View.GONE
homeRelative2.visibility = View.VISIBLE
}
else if(beacons.size==0) {
progress.visibility = View.GONE
homeRelative2.visibility = View.VISIBLE
}
}
companion object {
protected const val TAG = "RangingActivity"
}
fun startScan() {
try {
if (isScanFirstTime and beaconManager!!.isBound(this)) {
beaconManager!!.startRangingBeaconsInRegion(region)
isScanFirstTime = false
}
} catch (e: RemoteException) {
Log.d("startScanFunction", "Start scan beacon problem", e)
}
}
fun stopScan() {
try {
if (beaconManager!!.isBound(this)) {
beaconManager!!.stopRangingBeaconsInRegion(region)
}
} catch (e: RemoteException) {
Log.d("startScanFunction", "Stop scan beacon problem", e)
}
}
}
Expected behavior
iBeacon should not be detected when I disconnected .
Actual behavior
Altbeacon show iBeacon after I disconnected.
Steps to reproduce this behavior
Mobile device model and OS version
Android 9.0 Custom rom / Redmi note 3 pro
Android Beacon Library version
'org.altbeacon:android-beacon-library:2.17.1' Kotlin
Hey guys. I use altbeacon library for getting Ibeacon UUID. I use "beaconManager!!.addRangeNotifier " in onBeaconServiceConnect function. At first I launch my app and it can scan ibeacon correclty. for example 1 beacon is found. then after One time scan it is stopped. then I disconnect my Ibeacon power. it should not be found. but when I click on my Scan button, it still shows previous beacon. I must scan again and finally it is gone. It is something like get cached. I wanted and did it in fragment, it behaves similar. I write it in Activity again. nothing changed. I upload my code for you.