Advertisement
moonlightcheese

Untitled

Jul 13th, 2011
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. //in onCreate()
  2. mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  3. showNotification();
  4.  
  5. private void showNotification() {
  6.     Notification notification = new Notification(R.drawable.icon, "Scanner Service Started", System.currentTimeMillis());
  7.     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); //this is how we will launch an Activity when the user clicks the notification
  8.     notification.setLatestEventInfo(this, getText(R.string.app_name), "Scanner Not Connected", contentIntent);
  9.     notification.flags|=Notification.FLAG_ONGOING_EVENT;
  10.     mNM.notify(NOTIFICATION_CONNECTION_CHANGED, notification);  //send the notification to the system, to be displayed in the notification bar
  11. }
  12.  
  13. private void updateNotification(String update) {
  14.     Notification notification = new Notification(R.drawable.icon, update, System.currentTimeMillis());
  15.     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); //this is how we will launch an Activity when the user clicks the notification
  16.     notification.setLatestEventInfo(this, getText(R.string.app_name), update, contentIntent);
  17.     notification.flags|=Notification.FLAG_ONGOING_EVENT;
  18.     mNM.notify(NOTIFICATION_CONNECTION_CHANGED, notification);  //send the notification to the system, to be displayed in the notification bar
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement