Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Mastering Notifications in Android Applications

No description
by

Travis Himes

on 13 May 2014

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Mastering Notifications in Android Applications

Mastering Notifications in Android Applications
Travis Himes
What is a notification?
...it depends...
Pre-Honeycomb
Honeycomb+
3 different flavors, depending on OS version
JellyBean+
"What about 'Push Notifications'?"
These are not the notifications you're looking for...
Also referred to as C2DM and/or GCM
Standard
Notifications

JellyBean+
Big Picture
Inbox
Big Text
Let's build some notifications
NotificationCompat
Notification
Sound
Content
What can I control?
Vibration
Priority
Number
Actions
Delete
Text
Intent
Intent
LED
notification.number = 5
builder.setNumber(5)
n.tickerText = "..."
builder.setTicker("...")
n.title = "..."
builder.setContentTitle("...")
n.text = "..."
builder.setContentText("...")
You only have so much space for cont...
Ongoing
builder.setPriority(Notification.PRIORITY_MAX)

valid priorities: MAX, HIGH, LOW, DEFAULT, MIN





builder.setOngoing(true)
11
16
n.vibrate = new long[]{500L, 500L, 500L, 500L};
builder.setVibrate(new long[]{500L, 500L, 500L, 500L});
[msOff, msOn...]
Google says:

Don't use it unless your priority is MAX, HIGH, or DEFAULT

Any color other than white should be something the user has selected, not something you've determined
n.ledARGB = 0xFF00FF00
n.ledOnMS = 100
n.ledOffMS = 200
builder.setLights(0xFF0000FF, 100, 200)
The device has the right to just ignore your request!
n.audioStream or n.sound / builder.setSound
Intent intent = new Intent(...);

PendingIntent pi = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
What? Why?
n.contentIntent = intent;
n.setLatestEventInfo(context, title, text, intent)
builder.setContentIntent(intent)
n.deleteIntent / builder.setDeleteIntent
*requires the VIBRATE permission
JellyBean + ONLY
builder.addAction(R.drawable.ic_action_search,
"Begin Search!",
getPendingIntentForAction(context));
Suggestion: keep it to 3 or fewer at a time
Intent intent = new Intent(...);

PendingIntent pi = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
Custom Notifications
*Feel free to ask questions
RemoteViews!
Layouts:
LinearLayout
FrameLayout
RelativeLayout
Widgets:
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
StackView
+
=
Caveats:
No Descendants!
Max Height
preJellybean: 64dp
expanded: 256dp
Be careful, don't expect full control you're used to
Things to be aware of:
Ongoing notifications!
Canceling a dismissed or canceled notification is safe.
No built-in way to check on the current state of notifications.
(visible, dismissed, clicked, expired, expanded)
Circumvention is possible, but a pain
How would I do it if I had to?
Notification Intent Dispatcher
notification.deleteIntent
Notification Database
Icon style changes
Keep colors away from your icons
Questions?
A Notification's id is important
notifMgr.notify(idOfNotification); // will update, if the id matches
...
notifMgr.cancel(idOfNotification); // will remove notification
Can be a String or an int
What'd I get wrong?
Android Architect @ MeetMe
code: http://goo.gl/uJ3fMS
work @ MeetMe: http://goo.gl/miv1lV
Moto X
Active notifications
Limitations
circle mask on large icon
small icon in active notification
Icons
small icon (int)
large icon (bitmap)
Defaults
n.largeIcon / setLargeIcon(...)
n.icon / setSmallIcon(...)
vibration
sound
led
@travis_himes
@travis_himes
Can't be used pre-Honeycomb:
ListView
GridView
ViewFlipper
AdapterViewFlipper
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(android.R.drawable.ic_notification_clear_all)
.setLargeIcon(mySmallBitmap)
.setContentTitle("Hi Notification")
.setContentText("Just saying \"hi\"!")
.setContentIntent(getPendingIntentForNotification(context))
.addAction(android.R.drawable.ic_delete, "Delete", getPendingIntentForAction(context));

notifMgr.notify(0, builder.build());
Google Wear Notifications
Limitations
Circle form factor*

Abilities
Pages
Voice Input

Code!
Full transcript