Hi
I am a newer for estimote beacons and recently I tried to use the Android-Proximity-SDK to detect 3 beacons but now I face some problems.
-
When the smartphone moves close or far away the beacons I will get wrong information sometimes. For example I am moving from pink beacon to yellow one and I get ‘Previous you were near the pink beacon’ and then I get ‘Previous you were near the purple beacon’ which is totally wrong
I don’t know it’s due to the smartphones receiving capability or there are some bug in the code. I changed the working range in the code to make sure there is no overlapping of different range but I still get confusion information. One thing is the yellow beacon seems has stronger signal strength even I out of the range I can detect it. Also I saw some suggestions from forum and decreased the advertising interval from 1000ms to 200ms but the result didn’t change.
-
Could you please tell me the difference between using estimote API and Eddystone ?
-
Now the application is running in foreground how can I change it to background?
This is the main part of my code. Can someone answer my questions? Thank you in advance.
Blockquote
class MainActivity : AppCompatActivity() {
/** Fields in this class */
// Related to proximity methods
private lateinit var proximityObserver: ProximityObserver
private var proximityObservationHandler: ProximityObserver.Handler? = null
//private lateinit var proximityObservationHandler: ProximityObserver.Handler
// Could credentials found from https://cloud.estimote.com/
private val cloudCredentials = EstimoteCloudCredentials("laboratorium-dibris-gmail--kfg", "90e1b9d8344624e9c2cd42b9f5fd6392")
// Lambda functions for displaying errors when checking requirements
private val displayToastAboutMissingRequirements: (List<Requirement>) -> Unit = { Toast.makeText(this, "Unable to start proximity observation. Requirements not fulfilled: ${it.size}", Toast.LENGTH_SHORT).show() }
private val displayToastAboutError: (Throwable) -> Unit = { Toast.makeText(this, "Error while trying to start proximity observation: ${it.message}", Toast.LENGTH_SHORT).show() }
/** Methods in this class */
// onCreate method runs first (when an application is launched)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Requirements check
RequirementsWizardFactory.createEstimoteRequirementsWizard().fulfillRequirements(
this,
onRequirementsFulfilled = { startProximityObservation() },
onRequirementsMissing = displayToastAboutMissingRequirements,
onError = displayToastAboutError
)
}
// The method where you implement the logic for your application
private fun startProximityObservation() {
proximityObserver = ProximityObserverBuilder(applicationContext,cloudCredentials)
.onError(displayToastAboutError)
.withTelemetryReportingDisabled() //Added this to reduce the bluetooth call back traffic which was giving an error " Closed Bluetooth Low Energy scan failed with error code: 2"
.withAnalyticsReportingDisabled() //Similarly this
.withEstimoteSecureMonitoringDisabled() //Similarly this
.withBalancedPowerMode()
.build()
val pinkBeacon = ProximityZoneBuilder()
.forTag("pink1")
.inCustomRange(1.0)
.onEnter{
Log.d("Debug.. ", "Currently near the pink beacon")
textView.text = "Currently near pink beacon"
}
.onExit{
Log.d("Debug.. ", "Previously you were near the pink beacon")
textView.text = "Previously you were near pink beacon"
}
.build()
val purpleBeacon = ProximityZoneBuilder()
.forTag("purple2")
.inCustomRange(1.0)
.onEnter{
Log.d("Debug.. ", "Currently near the purple beacon")
textView.text = "Currently near purple beacon"
}
.onExit{
Log.d("Debug.. ", "Previously you were near the purple beacon")
textView.text = "Previously you were near purple beacon"
}
.build()
val yellowBeacon = ProximityZoneBuilder()
.forTag("yellow1")
.inCustomRange(2.0)
.onEnter{
Log.d("Debug.. ", "Currently near the yellow beacon")
textView.text = "Currently near yellow beacon"
}
.onExit{
Log.d("Debug.. ", "Previously you were near the yellow beacon")
textView.text = "Previously you were near yellow beacon"
}
.build()
proximityObservationHandler = proximityObserver.startObserving(pinkBeacon, purpleBeacon, yellowBeacon)
}
// onDestroy method runs last (when an application is closed)
// IMPORTANT (This applies for mobile app):
// If you don't stop the scan here, the foreground service will remain active EVEN if the user kills your APP.
// You can use it to retain scanning when app is killed, but you will need to handle actions properly.
override fun onDestroy() {
proximityObservationHandler?.stop()
super.onDestroy()
}
}