Skip to content

Instantly share code, notes, and snippets.

@qhm123
Created December 3, 2012 03:50
Show Gist options
  • Save qhm123/4192565 to your computer and use it in GitHub Desktop.
Save qhm123/4192565 to your computer and use it in GitHub Desktop.
How exactly to use Notification.Builder
Intent notificationIntent = newIntent(ctx, YourClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(ctx,
YOUR_PI_REQ_CODE, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
NotificationManager nm = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
Resources res = ctx.getResources();
Notification.Builder builder = newNotification.Builder(ctx);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.some_img)
.setLargeIcon(
BitmapFactory.decodeResource(res,
R.drawable.some_big_img))
.setTicker(res.getString(R.string.your_ticker))
.setWhen(System.currentTimeMillis()).setAutoCancel(true)
.setContentTitle(res.getString(R.string.your_notif_title))
.setContentText(res.getString(R.string.your_notif_text));
Notification n = builder.build();
nm.notify(YOUR_NOTIF_ID, n);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment