Skip to content

Instantly share code, notes, and snippets.

@scraplesh
Created November 10, 2021 10:06
Show Gist options
  • Select an option

  • Save scraplesh/5592e694511efda2594b98e14ec540e8 to your computer and use it in GitHub Desktop.

Select an option

Save scraplesh/5592e694511efda2594b98e14ec540e8 to your computer and use it in GitHub Desktop.
class UdpActivity : AppCompatActivity(), NavigineNotification.Listener {
private lateinit var binding: ActivityMtsliveBinding
private var subLoc: SubLocation? = null
private val locationId = 98872
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMtsliveBinding.inflate(layoutInflater)
.apply { setContentView(root) }
initNavigine()
startListeningNotifications()
}
override fun onNotificationReceived(context: Context, notification: NavigineNotification) {
Log.d("SYNC", "Beacon id = ${notification.id}, content = ${notification.content}")
Snackbar.make(
this,
binding.root,
"Beacon id = ${notification.id}, content = ${notification.content}",
Snackbar.LENGTH_LONG
).show()
}
private fun initNavigine() {
if (!NavigineSDK.isInitialized()) {
NavigineSDK.setParameter(this, "actions_updates_enabled", true)
NavigineSDK.setParameter(this, "navigine_service_wakeup_interval", 1)
NavigineSDK.setParameter(this, "navigine_service_wakeup_timeout", 1)
NavigineSDK.setParameter(this, "navigine_service_enabled", true)
NavigineSDK.setParameter(this, "notifications_enabled", true)
NavigineSDK.initialize(this, "****-****-****-****", null)
NavigineSDK.getNavigation().mode = NavigationThread.MODE_NORMAL
}
}
private fun startListeningNotifications() {
Log.d("SYNC", "Started listening beacon notifications")
NavigationHelper.setNotificationListener(this)
Log.d("SYNC", "Started loading location $locationId")
NavigineSDK.loadLocationInBackground(locationId, object : Location.LoadListener() {
override fun onFinished() {
Log.d("SYNC", "Location $locationId loaded successfully")
Snackbar.make(
this@UdpActivity,
binding.root,
"Location $locationId loaded successfully",
Snackbar.LENGTH_LONG
).show()
}
override fun onFailed(error: Int) {
super.onFailed(error)
Log.e("SYNC", "Failed loading location $locationId")
Snackbar.make(
this@UdpActivity,
binding.root,
"Failed loading location $locationId",
Snackbar.LENGTH_LONG
).show()
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment