A simple project to add an "Add to Pocket" action to your Android Wear notifications, with just one line of code.
PocketWearableNotificationUtil.addPocketAction(wearableBuilder, notifyId, url, null, context);
Android's Wear APIs are in a Developer Preview and may change at any time. This Pocket SDK should also be considered a work in progress. Also, we strongly encourage you to follow the Wear Design Guidelines and only push content to a user's wearable if they have asked to receive such notifications.
-
Add the project contained in "library" as an Android Library Project. (Here's how to from Eclipse and from the Command Line)
-
Add the Android Wear SDK jar to the build path of the Library Project. In order to get this jar you must sign up for the Developer Preview.
-
Add the latest version of the Android Support Library to the Library Project. How to install.
-
Add a reference to
PocketIntentReceiver
in yourAndroidManifest.xml
file withinapplication
.
<receiver android:name="com.pocket.util.PocketIntentReceiver" android:exported="false">
<intent-filter>
<action android:name="com.pocket.wear.ACTION_ADD_TO_POCKET" />
</intent-filter>
</receiver>
First create your WearableNotifications.Builder
like you normally would. For example:
String url = "http://bicepkeck.org/";
int notifyId = 5;
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setContentTitle("Sigma 5.9!")
.setContentText("BICEP2 announces breakthrough")
.setSmallIcon(R.drawable.ic_notification_icon);
WearableNotifications.Builder wearableBuilder = new WearableNotifications.Builder(builder);
Then, to add the Pocket action, all you need to do is:
PocketWearableNotificationUtil.addPocketAction(wearableBuilder, notifyId, url, null, context);
If Pocket is installed on the user's device, it will add the action. If not, nothing will be added to the builder.
The url
is whatever link that should be saved to Pocket if the uses taps the action. The notifyId
should be the id you later use to show the notification. For example:
NotificationManagerCompat.from(context).notify(notifyId, wearableBuilder.build());