blob: 42237de3e0d70ae339a91229f29525fa76f21cc4 [file] [log] [blame]
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.wearable.findphone;
import android.app.Notification;
import android.app.NotificationManager;
import com.google.android.gms.wearable.WearableListenerService;
/**
* Listens for disconnection from home device.
*/
public class DisconnectListenerService extends WearableListenerService {
private static final String TAG = "ExampleFindPhoneApp";
private static final int FORGOT_PHONE_NOTIFICATION_ID = 1;
@Override
public void onPeerDisconnected(com.google.android.gms.wearable.Node peer) {
// Create a "forgot phone" notification when phone connection is broken.
Notification.Builder notificationBuilder = new Notification.Builder(this)
.setContentTitle(getString(R.string.left_phone_title))
.setContentText(getString(R.string.left_phone_content))
.setVibrate(new long[] {0, 200}) // Vibrate for 200 milliseconds.
.setSmallIcon(R.drawable.ic_launcher)
.setLocalOnly(true)
.setPriority(Notification.PRIORITY_MAX);
Notification card = notificationBuilder.build();
((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
.notify(FORGOT_PHONE_NOTIFICATION_ID, card);
}
@Override
public void onPeerConnected(com.google.android.gms.wearable.Node peer) {
// Remove the "forgot phone" notification when connection is restored.
((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
.cancel(FORGOT_PHONE_NOTIFICATION_ID);
}
}