Hi!
I’m having a problem with estimotes proximity. I have downloaded the package example for my projeto (after create a new app thrown the estimote Cloud) and put in my phone to check if it work or not.
What i check is that the range, by default, is set to 3.0, but when i put the app on my phone, a received both of Hello notification and Goodbye notification. The GoodBye notification must open only after a get out of this range (3). What is wrong?
I didnt change anything, a just download the app and create the .apk to verify the funcionality.
Codes:
class MyApplication : Application() {
val cloudCredentials = EstimoteCloudCredentials("proximitypush-cwj", "KEY_OF_APP")
fun enableBeaconNotifications() {
val notificationsManager = NotificationsManager(this)
notificationsManager.startMonitoring()
}
}
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val app = application as MyApplication
RequirementsWizardFactory
.createEstimoteRequirementsWizard()
.fulfillRequirements(this,
onRequirementsFulfilled = {
Log.d("app", "requirements fulfilled")
app.enableBeaconNotifications()
},
onRequirementsMissing = { requirements ->
Log.e("app", "requirements missing: " + requirements)
},
onError = { throwable ->
Log.e("app", "requirements error: " + throwable)
})
}
}
class NotificationsManager(private val context: Context) {
private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
private val helloNotification = buildNotification("Hello", "You're near your beacon")
private val goodbyeNotification = buildNotification("Bye bye", "You've left the proximity of your beacon")
private fun buildNotification(title: String, text: String): Notification {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.createNotificationChannel(NotificationChannel(
"content_channel", "Things near you", NotificationManager.IMPORTANCE_HIGH))
}
return NotificationCompat.Builder(context, "content_channel")
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle(title)
.setContentText(text)
.setContentIntent(PendingIntent.getActivity(context, 0,
Intent(context, MainActivity::class.java), PendingIntent.FLAG_UPDATE_CURRENT))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.build()
}
fun startMonitoring() {
val notificationId = 1
val proximityObserver = ProximityObserverBuilder(context, (context as MyApplication).cloudCredentials)
.onError { throwable ->
Log.e("app", "proximity observer error: $throwable")
}
.withBalancedPowerMode()
.build()
val zone = ProximityZoneBuilder()
.forTag("proximitypush-cwj")
.inCustomRange(2.0)
.onEnter {
notificationManager.notify(notificationId, helloNotification)
}
.onExit {
notificationManager.notify(notificationId, goodbyeNotification)
}
.build()
proximityObserver.startObserving(zone)
}
}