Reader small image

You're reading from  Mastering Android Wear Application Development

Product typeBook
Published inDec 2016
Reading LevelIntermediate
PublisherPackt
ISBN-139781785881725
Edition1st Edition
Languages
Right arrow
Authors (2):
Siddique Hameed
Siddique Hameed
author image
Siddique Hameed

Siddique Hameed is a pragmatic technologist currently working on Simplify Commerce (https://simplify.com), a payment gateway platform from MasterCard. During his diverse career roles, hes been crafting software for Fortune 500 companies to startups of industry domains ranging from finance, commerce, social media, telecom, bioinformatics, publishing, and insurance. He is passionate about technology, software and their effects on day-to-day lives. He is a strong believer in open-source software culture and actively contributes to many opensource projects. On times, he speaks at technology events, meetups, and mentor contestants in hackathons. He likes teaching kids and adults in programming, technology and software development, and volunteers on coding initiatives such as Girls Who Code, Code.org, and STEM (science, technology, engineering, and mathematics) programs. In his spare time, he likes traveling, goes on long road trips, and tinker with Raspberry Pi and build DIY gadgets.
Read more about Siddique Hameed

Javeed Chida
Javeed Chida
author image
Javeed Chida

Javeed Chida currently works as a senior software engineer for Apollo Education Group, a leader in global education. He has worked with several teams over the years developing multi-layered enterprise applications for companies spanning several industries including education, finance, medical, insurance, construction, and legal. He is passionate about Java portals and particularly enthused by the Liferay portal platform. He also has a love for clever and innovative technical documentation. Apart from periodically churning out articles as a highlighted community blogger on Liferay.com. He spends his leisure absorbed in creative writing projects, particularly classical poetry and fiction.
Read more about Javeed Chida

View More author details
Right arrow

Chapter 6.  Contextual Notifications

 

"Life is about timing."

 
 --Carl Lewis

In this chapter, we will discuss notifications in Android Wear. After a quick comparison between notifications in wearable and handheld devices, we will continue extending the Today app from the previous chapter to demonstrate the Android Wear notifications API.

Note

The code accompanying this chapter is available for reference on GitHub (https://github.com/siddii/mastering-android-wear/tree/master/Chapter_6). For the sake of brevity, only code snippets are included as needed. The reader is encouraged to download the referenced code from GitHub and follow along as they progress through the chapter.

Getting notified


It should come as no surprise that wearable devices are naturally superior to handheld devices in their capacity to deliver notifications to the user. With a handheld device, you hear a beep, and you need to draw your device out from your purse or pocket or whatever choice holster you snagged at that recent eBay auction.

But with a smartwatch, things are quite different. When you hear that beep, you simply glance at your wrist. This ease is a hallmark feature of wearable device technology.

And it doesn't end there. With the help of voice interactions, the user can act on that notification by issuing a recognizable voice command. The voice interactions API, of course, predates the Wear API and has been in use on handheld devices for some time. But there is no denying the immense value it brings to wearable devices, fitting in perfectly with that ease of access. We'll deal with voice interactions in the next chapter.

So central is the notification model to wearable devices that...

Today app with to-do notifications


We are going to augment our Today app with a to-do activity that lets the user add to-do items and associate them with specific locations, such as home, or work. The locations then provide the context, which drives the notifications. This, in effect, makes our notifications context-aware.

For example, if the system detects that the user is in close proximity to the Home location, then to-do items associated with the Home category are presented to the user via the notifications API.

Geofencing

We'll be using the Geofencing API to figure out the location, that is, the context. In essence, this API lets us draw a circle of some agreed-upon radius around a coordinate. In effect, the latitude, longitude, and radius together define a geofence, a circular region around the coordinates of interest. Entrance and exit events signal when the device enters or exits the geofence location. An optional duration attribute delays the triggering of an event for that time interval...

To-do list view


The following figure depicts what the to-do list view looks like. Users can add to-do items, and delete existing ones. Each item in the list is displayed, along with its location:

Adding to-do items


The following image shows sample input for adding a new to-do item to the Today-Todo app:

Mock locations

You may have noticed that we chose to define two locations—home and work. Now, because we have high aspirations, we have ventured to build this app with the most deserving individual in mind, namely the President of the United States. So, that is why the home coordinates correspond to that of the White House, and the work coordinates correspond to that of Capitol Hill (Okay, bad example, we know. The President works in the Oval office in the west wing of the White House complex. But then, imagine how pointless our sample code would be if Work and Home had the same coordinates?). The Constants file with these values is shown in the following figure:

Mocking locations using FakeGPS app

Launch the FakeGPS app and search for the location White House as follows:

After you tap the Set location button, FakeGPS will proceed to simulate the location we set. Take note of the...

Summary


In this chapter, we extended the Today app to have a to-do activity. We use that extension to demonstrate context-aware notifications using the Notifications API. The notifications were displayed on the mobile device as well as the wearable device emulator. We introduced the concept of geofencing and used the Geofencing API along with a FakeGPS app to simulate our location.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Android Wear Application Development
Published in: Dec 2016Publisher: PacktISBN-13: 9781785881725
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Siddique Hameed

Siddique Hameed is a pragmatic technologist currently working on Simplify Commerce (https://simplify.com), a payment gateway platform from MasterCard. During his diverse career roles, hes been crafting software for Fortune 500 companies to startups of industry domains ranging from finance, commerce, social media, telecom, bioinformatics, publishing, and insurance. He is passionate about technology, software and their effects on day-to-day lives. He is a strong believer in open-source software culture and actively contributes to many opensource projects. On times, he speaks at technology events, meetups, and mentor contestants in hackathons. He likes teaching kids and adults in programming, technology and software development, and volunteers on coding initiatives such as Girls Who Code, Code.org, and STEM (science, technology, engineering, and mathematics) programs. In his spare time, he likes traveling, goes on long road trips, and tinker with Raspberry Pi and build DIY gadgets.
Read more about Siddique Hameed

author image
Javeed Chida

Javeed Chida currently works as a senior software engineer for Apollo Education Group, a leader in global education. He has worked with several teams over the years developing multi-layered enterprise applications for companies spanning several industries including education, finance, medical, insurance, construction, and legal. He is passionate about Java portals and particularly enthused by the Liferay portal platform. He also has a love for clever and innovative technical documentation. Apart from periodically churning out articles as a highlighted community blogger on Liferay.com. He spends his leisure absorbed in creative writing projects, particularly classical poetry and fiction.
Read more about Javeed Chida