Skip to content

Instantly share code, notes, and snippets.

@Mrono
Created August 14, 2013 02:43
Show Gist options
  • Save Mrono/6227588 to your computer and use it in GitHub Desktop.
Save Mrono/6227588 to your computer and use it in GitHub Desktop.
Create notification
createNotification(Context, String, String);
public static void createNotification(Context context, String title, String message) {
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,
"Alert: "+title, System.currentTimeMillis());
Intent intent = new Intent(context, MessageReceivedActivity.class);
intent.putExtra("title", title);
intent.putExtra("message", message);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, 0);
notification.setLatestEventInfo(context, title,
message, pendingIntent);
// long[] vibrate = {0,100,200,300};
// notification.vibrate = vibrate;
// notification.number = 2;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment