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.

Revisions

  1. scraplesh created this gist Nov 10, 2021.
    65 changes: 65 additions & 0 deletions navigine.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    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()
    }
    })
    }

    }