Skip to content

Instantly share code, notes, and snippets.

@Younes-Charfaoui
Created June 9, 2020 18:56
Show Gist options
  • Select an option

  • Save Younes-Charfaoui/cb17285338dcfbb2e1111d459769dce4 to your computer and use it in GitHub Desktop.

Select an option

Save Younes-Charfaoui/cb17285338dcfbb2e1111d459769dce4 to your computer and use it in GitHub Desktop.
// creating the pending intent
val intent = Intent(DetectedActivityReceiver.RECEIVER_ACTION)
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0)
// creating the receiver
receiver = DetectedActivityReceiver()
// registring the receiver
LocalBroadcastManager.getInstance(this).registerReceiver(
receiver, IntentFilter(DetectedActivityReceiverRECEIVER_ACTION)
)
val task = ActivityRecognition.getClient(this)
.requestActivityTransitionUpdates(finalRequest, pendingIntent)
task.addOnSuccessListener {
Log.d("ActivityRecognition", "Transitions Api registered with success")
}
task.addOnFailureListener { e: Exception ->
Log.d("ActivityRecognition", "Transitions Api could NOT be registered ${e.localizedMessage}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment