Guest User

Untitled

a guest
Jul 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. class TransitionRecognitionReceiver : BroadcastReceiver() {
  2.  
  3. lateinit var mContext: Context
  4.  
  5. override fun onReceive(context: Context?, intent: Intent?) {
  6. mContext = context!!
  7.  
  8. if (ActivityTransitionResult.hasResult(intent)) {
  9. var result = ActivityTransitionResult.extractResult(intent)
  10. processTransitionResult(result)
  11. }
  12. }
  13.  
  14. fun processTransitionResult(result: ActivityTransitionResult) {
  15. for (event in result.transitionEvents) {
  16. onDetectedTransitionEvent(event)
  17. }
  18. }
  19.  
  20. private fun onDetectedTransitionEvent(activity: ActivityTransitionEvent) {
  21. when (activity.activityType) {
  22. DetectedActivity.ON_BICYCLE,
  23. DetectedActivity.RUNNING,
  24. DetectedActivity.WALKING -> {
  25. // Make whatever you want with the activity
  26. }
  27. else -> {
  28. }
  29. }
  30. }
  31. }
Add Comment
Please, Sign In to add comment