Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send notification from handheld to wear to open Activity on wear device

I'm wondering if it is possible to send notification from handheld (android phone) to wear device to open Activity on wear device? What I want to do is as following.

enter image description here

So far, I checked the following documents, but it's different from what I want to do.

  • Adding Wearable Features to Notifications
    • What is described here is sending notification from phone to wear, then open activity on the phone (I want to open activity on the wear)
  • Create Custom Notifications
    • What is described here is sending notification from wear to wear, then open activity on the wear (I want to send notification from phone to wear)

Any ideas?

like image 644
Poly Avatar asked Jul 08 '14 06:07

Poly


People also ask

What does App Notifier do?

An app notification is a message or alert sent by an application to the device user. They include push notifications and in-app notifications.

Why am I not getting notifications on my fossil smartwatch?

You should make sure your device battery has power and your device is connected properly to the app. Your app must be running in the background for notifications to properly work. If the problem persists you may unpair your device from the phone and pair it again.

What is Notificationcompat builder in Android?

Allows easier control over all the flags, as well as help constructing the typical notification layouts. On platform versions that don't offer expanded notifications, methods that depend on expanded notifications have no effect. For example, action buttons won't appear on platforms prior to Android 4.1.


2 Answers

The pattern to use for this is:

  1. Create a DataItem on the mobile. It will be synced to the connected wearable automatically.
  2. On the wearable, implement a WearableListenerService and listen for onDataChanged events.
  3. When you receive a DataItem, create a notification (with the data sent in the DataItem) and send it locally (i.e. on the wearable). Use setContentIntent() on the notification to specify a pending intent that will launch your wearable activity.
  4. Don't forget to also provide an intent that is fired when the user dismisses the notification on the wearable, so that the DataItem can be removed. Otherwise, you will not receive any update events.

I've created a sample project that shows all of this in action.

Check out this question if the onDataChanged method is not getting called.

like image 71
Peter Friese Avatar answered Oct 11 '22 17:10

Peter Friese


I think in most cases it would be better to include your app activity inside the notification. For example, instead of the "Open" button in your notification, you could use setDisplayIntent(notificationPendingIntent) to display an activity as part of the notification as described here: http://developer.android.com/training/wearables/apps/layouts.html

This gives you a best of both worlds situation between having an app and a notification.

like image 41
Graydyn Young Avatar answered Oct 11 '22 17:10

Graydyn Young