Return to Video

onHandleIntent Helper - Solution

  • 0:01 - 0:03
    So here you can see I'm getting
    the list of geofences and
  • 0:03 - 0:05
    I'm going to call it
    triggeringGeoFences.
  • 0:05 - 0:09
    And I get this by calling
    the getTriggeringGeoFences method on my
  • 0:09 - 0:11
    geofencing event.
  • 0:11 - 0:14
    So no matter how many geofences have
    been triggered, be it one, be it many,
  • 0:14 - 0:17
    they will return to this
    list of geofences for me.
  • 0:18 - 0:22
    Now the getGeoFenceTransitionDetails
    helper function.
  • 0:22 - 0:24
    We'll turn all of these into a string.
  • 0:24 - 0:27
    So, I just say string,
    geofenceTransitionDetails equals
  • 0:27 - 0:31
    getGeofenceTransitionDetails, and
    I pass at this,
  • 0:31 - 0:36
    I pass at my geofenceTransition, and
    I pass at my triggeringGeofences.
  • 0:36 - 0:38
    Let's take a look at this function.
  • 0:38 - 0:40
    Here's the getGeofenceTransitionDetails.
  • 0:40 - 0:44
    And you can see it takes the context and
    it takes the geofenceTransition,
  • 0:44 - 0:45
    which was just an integer.
  • 0:45 - 0:49
    And it takes a list of geofences,
    which are my triggeringGeofences.
  • 0:49 - 0:52
    So first of all I'm going to
    get the transition string for
  • 0:52 - 0:53
    my actual transition.
  • 0:53 - 0:57
    And I'm just going to call that
    string geofenceTransitionString.
  • 0:57 - 1:00
    And then I'm going to iterate
    through each of my geofences,
  • 1:00 - 1:02
    and get a string out of them.
  • 1:02 - 1:06
    Load that string into an array list and
    then use TextUtils.join on that
  • 1:06 - 1:10
    array list to join all of those strings
    together and to concatenate them.
  • 1:10 - 1:13
    There are a number of ways
    that you could do this, but
  • 1:13 - 1:15
    ultimately what you're
    interested in is this.
  • 1:15 - 1:18
    The geofence.getRequestId.
  • 1:18 - 1:21
    This gives you the ID of the geofence
    that triggered the event and
  • 1:21 - 1:24
    it's up to you how you would
    handle that ID, in this case.
  • 1:24 - 1:28
    Like I said, I'm just concatenating
    them all together, so,
  • 1:28 - 1:31
    if there were a number of
    different geofences triggered,
  • 1:31 - 1:34
    I would get their IDs all listed in
    this single notification, saying, for
  • 1:34 - 1:37
    example, Lawrence has
    entered Mountain View.
  • 1:37 - 1:39
    Lawrence has entered entered
    the Audacity Studios.
  • 1:39 - 1:41
    Lawrence has entered Studio X.
  • 1:41 - 1:44
    That type of thing all in a single
    notification instead of multiple
  • 1:44 - 1:46
    notifications.
  • 1:46 - 1:49
    And then, as a result, I just return
    my geofenceTransitionString and
  • 1:49 - 1:51
    the list of IDs that came.
  • 1:51 - 1:55
    So it would be entered plus the list or
    exited plus the list.
  • 1:55 - 1:56
    That type of thing.
  • 1:56 - 1:58
    So this helper function
    achieves all of that for you.
Tytuł:
onHandleIntent Helper - Solution
Opis:

more » « less
Video Language:
English
Team:
Udacity
Projekt:
UD876-1 - Google Play Services - Location & Contex

English subtitles

Revisions Compare revisions