Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 0.99 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to write onclick llistener for notification item in android?
  2. mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  3. final Notification notifyDetails = new Notification(R.drawable.android,"New Alert, Click Me!",System.currentTimeMillis());
  4. Context context = getApplicationContext();
  5. CharSequence contentTitle = "Notification Details...";
  6. CharSequence contentText = "Browse Android Official Site by clicking me";              
  7. Intent notifyIntent = new Intent(Intent.ACTION_MAIN);
  8. notifyIntent.setComponent(new ComponentName("mypackage","mypackage.ActivityB"));
  9.  
  10. PendingIntent intent = PendingIntent.getActivity(SimpleNotification.this, 0,notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
  11. notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
  12. mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
  13.        
  14. Intent notifyIntent = new Intent(this, ActivityB.class); // 'this' - Context object
  15.        
  16. intent.putExtra("yourTag", yourVariable);