1 /* 2 * Copyright 2015 Google Inc. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.xyztouristattractions.service; 18 19 import android.content.Intent; 20 import android.net.Uri; 21 import android.util.Log; 22 23 import com.example.android.xyztouristattractions.ui.DetailActivity; 24 import com.google.android.gms.wearable.MessageEvent; 25 import com.google.android.gms.wearable.WearableListenerService; 26 import com.example.android.xyztouristattractions.common.Constants; 27 28 /** 29 * A Wear listener service, used to receive inbound messages from 30 * the Wear device. 31 */ 32 public class ListenerService extends WearableListenerService { 33 private static final String TAG = ListenerService.class.getSimpleName(); 34 35 @Override 36 public void onMessageReceived(MessageEvent messageEvent) { 37 Log.v(TAG, "onMessageReceived: " + messageEvent); 38 39 if (Constants.CLEAR_NOTIFICATIONS_PATH.equals(messageEvent.getPath())) { 40 // Request for this device to clear its notifications 41 UtilityService.clearNotification(this); 42 } else if (Constants.START_ATTRACTION_PATH.equals(messageEvent.getPath())) { 43 // Request for this device open the attraction detail screen 44 // to a specific tourist attraction 45 String attractionName = new String(messageEvent.getData()); 46 Intent intent = DetailActivity.getLaunchIntent(this, attractionName); 47 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 48 startActivity(intent); 49 } else if (Constants.START_NAVIGATION_PATH.equals(messageEvent.getPath())) { 50 // Request for this device to start Maps walking navigation to 51 // specific tourist attraction 52 String attractionQuery = new String(messageEvent.getData()); 53 Uri uri = Uri.parse(Constants.MAPS_NAVIGATION_INTENT_URI + Uri.encode(attractionQuery)); 54 Intent intent = new Intent(Intent.ACTION_VIEW, uri); 55 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 56 startActivity(intent); 57 } 58 } 59 } 60