What do I use now that BootstrapNotifier interface is deprecated in IBEACON?
Ibeacon deprecated : 1) RegionBootstrap 2) BootstrapNotifier 3) BackgroundPowerSaver
is there any alternate solution or reference link? I shared my full code
import android.annotation.SuppressLint
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.NotificationCompat
import org.altbeacon.beacon.BeaconManager
import org.altbeacon.beacon.Region
import org.altbeacon.beacon.powersave.BackgroundPowerSaver
import org.altbeacon.beacon.startup.BootstrapNotifier
import org.altbeacon.beacon.startup.RegionBootstrap
class MainActivity2 : AppCompatActivity(), BootstrapNotifier {
private var regionBootstrap: RegionBootstrap? = null
private var backgroundPowerSaver: BackgroundPowerSaver? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// showNotification(this,"found beacon init")
//enable beacon features///////////////////////////////////////////////////////////////////////
val beaconManager: BeaconManager = BeaconManager.getInstanceForApplication(this)
beaconManager.beaconParsers.clear()
beaconManager.beaconParsers
.add(org.altbeacon.beacon.BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"))
beaconManager.setEnableScheduledScanJobs(false) // disable JobScheduler-based scans (used on Android 8+)
beaconManager.backgroundBetweenScanPeriod = 0 // set the time between each scan to be 1 hour (3600 seconds)
beaconManager.backgroundScanPeriod = 1100 // set the duration of the scan to be 1.1 seconds
val region = Region("backgroundRegion", null, null, null)
regionBootstrap = RegionBootstrap(this, region) // wake up the app when a beacon is seen
backgroundPowerSaver = BackgroundPowerSaver(this) //This reduces bluetooth power usage by about 60%
//////////////////////////////////////////////////////////////////////////////////////////////
}
override fun didEnterRegion(arg0: Region?) {
Log.d("mybeacon", "i found a enter")
showNotification(this,"found beacon enter")
}
override fun didExitRegion(region: Region?) {
Log.d("mybeacon", "i found a exit")
showNotification(this,"found beacon exit")
}
override fun didDetermineStateForRegion(state: Int, region: Region?) {}
//............................................................
fun showNotification(context: Context, message: String?) {
}
}
implementation :
implementation 'org.altbeacon:android-beacon-library:2.19.3'
Library version 2.19+ introduces autowind APIs that make setting up beacon scanning much simpler, more intuitive and less prone to configuration errors.
In earlier versions of the library, auto-launch of an app on beacon detection was handled by the RegionBootstrap
utility class, but as of 2.19 it is no longer necessary -- you simply start monitoring with startMonitoring(region)
. The library sample code shows an example of how to start up auto-launch section of the code samples
To start up beacon scanning in the background simply replace regionBootstrap = RegionBootstrap(this, region)
with this:
beaconManager.addMonitorNotifier(this)
beaconManager.startMonitoring(region)
Instead of the BootstrapNotifier
interface, your class should implement MonitorNotifier
.
While it is unrelated to the autobind API changes in 2.19, be aware that if you want the library to automatically launch your app on beacon detection, you must implement the above code in the onCreate
method of a custom Android Application class and not an Activity as shown in the question. If you don't care about auto launch, then doing this in an Activity class is fine.