1 /* 2 * Copyright (C) 2014 The Android Open Source Project 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.wearable.findphone; 18 19 import android.app.Notification; 20 import android.app.NotificationManager; 21 22 import com.google.android.gms.wearable.WearableListenerService; 23 24 /** 25 * Listens for disconnection from home device. 26 */ 27 public class DisconnectListenerService extends WearableListenerService { 28 29 private static final String TAG = "ExampleFindPhoneApp"; 30 31 private static final int FORGOT_PHONE_NOTIFICATION_ID = 1; 32 33 @Override 34 public void onPeerDisconnected(com.google.android.gms.wearable.Node peer) { 35 // Create a "forgot phone" notification when phone connection is broken. 36 Notification.Builder notificationBuilder = new Notification.Builder(this) 37 .setContentTitle(getString(R.string.left_phone_title)) 38 .setContentText(getString(R.string.left_phone_content)) 39 .setVibrate(new long[] {0, 200}) // Vibrate for 200 milliseconds. 40 .setSmallIcon(R.drawable.ic_launcher) 41 .setLocalOnly(true) 42 .setPriority(Notification.PRIORITY_MAX); 43 Notification card = notificationBuilder.build(); 44 ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) 45 .notify(FORGOT_PHONE_NOTIFICATION_ID, card); 46 } 47 48 @Override 49 public void onPeerConnected(com.google.android.gms.wearable.Node peer) { 50 // Remove the "forgot phone" notification when connection is restored. 51 ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) 52 .cancel(FORGOT_PHONE_NOTIFICATION_ID); 53 } 54 55 } 56