Notification window

Put your problem here if it does not fit any of the other categories.

Notification window

Postby soumen4code » Fri Apr 15, 2011 7:26 am

I have a app where some notification is coming to the notification status bar for incoming emails, . There is no problem it is coming properly, and when I pull the notification window down then also there is no problem the notification is there in the window . But when I touch the notification it is just gone. There is the problem lies . I want that when I click on the notification in the notification window it should perform some action. suppose it will launch the inbox.
soumen4code
Developer
Developer
 
Posts: 46
Joined: Wed Mar 16, 2011 4:21 pm

Top

Re: Notification window

Postby imbroken » Fri Apr 15, 2011 8:16 am

When creating your notification, you need to set the pending intent in that notification. That is the intent that is fired when you click on the icon in the notification bar.
This is done by Notification.setLatestEventInfo(...)
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Re: Notification window

Postby soumen4code » Fri Apr 15, 2011 8:41 am

Can u provide me some example? it will be very helpful.
soumen4code
Developer
Developer
 
Posts: 46
Joined: Wed Mar 16, 2011 4:21 pm

Re: Notification window

Postby imbroken » Fri Apr 15, 2011 8:49 am

Code: Select all
Intent intent = new Intent(this, ActivityToLoad.class);
PendingIntent startIntent = PendingIntent.getActivity(   getBaseContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(getBaseContext(), "Your title", "Your description", startIntent);
notificationManager.notify(notificationId, notification);
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Re: Notification window

Postby soumen4code » Fri Apr 15, 2011 9:06 am

I hve done this but it is not loading the notification file.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Notification notification = new Notification(icon, sms1, when);
  2.                         Intent intent1 = new Intent(context, NotificationViewer.class);
  3.                         PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent1, PendingIntent.FLAG_ONE_SHOT);
  4.                         notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
  5.                         //notification.vibrate = new long[] { 100, 250, 100, 500};
  6.                         notification.flags |= Notification.FLAG_AUTO_CANCEL;
  7.                         mNotificationManager.notify(1, notification);
  8.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


This above code is inside of onRecive() method. And the NotificationViewer.class is given below.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package mypack.mydemos.demo;
  2.  
  3. import android.app.Activity;
  4. import android.app.NotificationManager;
  5. import android.content.Context;
  6. import android.os.Bundle;
  7. import android.widget.Toast;
  8.  
  9. public class NotificationViewer extends Activity {
  10.  
  11.         @Override
  12.         protected void onCreate(Bundle savedInstanceState) {
  13.                 super.onCreate(savedInstanceState);
  14.                 setContentView(R.layout.notification_viewer);
  15.                
  16.                 NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
  17.                
  18.                 notificationManager.cancel(Constants.NOTIFICATION_ID);
  19.                
  20.                
  21.                
  22.                 Toast.makeText(this,"Directory Exists ", Toast.LENGTH_LONG).show();
  23.  
  24.         }
  25.  
  26. }
  27.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4



But not getting the toast form NotficationViewerClass. "Imbroken" can you help me to fix it...
soumen4code
Developer
Developer
 
Posts: 46
Joined: Wed Mar 16, 2011 4:21 pm

Re: Notification window

Postby imbroken » Fri Apr 15, 2011 3:51 pm

Never shown? Not even once when the actuvity is created?

Because if its fire once the actived would be resumed and never reached onCreate.
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests