Created
August 14, 2013 02:43
-
-
Save Mrono/6227588 to your computer and use it in GitHub Desktop.
Create notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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