Question

all i this is my code in notification class which i am calling after completing my tasks from 1st activity.

But i am getting the problem for getting notification on current application.

I want to show Notification as dialog box.

"R.layout.main" 

contains dialog box with OK button.

public class Notif extends Activity implements View.OnClickListener {

  private Button Button01;

  private NotificationManager mManager;

  private static final int APP_ID = 0; 

  @Override

  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    this.Button01 = (Button) this.findViewById( R.id.Button1);

    this.Button01.setOnClickListener(this);



    mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

  }

  @Override

  public void onClick(View v) {

    Intent intent = new Intent(this,Notif.class);
    Notification notification = new Notification(R.drawable.icon,

    "Notify", System.currentTimeMillis());

       notification.setLatestEventInfo(Notif.this,"App Name","Description of the                     notification",PendingIntent.getActivity(this.getBaseContext(), 0, intent,

PendingIntent.FLAG_CANCEL_CURRENT));

    mManager.notify(APP_ID, notification);

  }

}
Was it helpful?

Solution

1) Why handle your button listener with an implementation of View.OnClickListener?

The standard way I have seen so far is:

    Button01.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Your code
        }
    });

2) Notifications are ways to notify the user through the Android status panel at the top of the screen. I don't understand what you want to do with Notifications and Dialog Boxes - make up your mind which one you want?

http://developer.android.com/guide/topics/ui/dialogs.html

http://developer.android.com/guide/topics/ui/notifiers/notifications.html

If you do want to use Notifications, then this is what I have in my onStop() method (it's basically just what you get from following the Android guide):

        Notification notification = new Notification(R.drawable.icon, "App Name", System.currentTimeMillis());
        notification.flags = Notification.FLAG_AUTO_CANCEL;

        Intent notificationIntent = new Intent(this, ClassToStart.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        notification.setLatestEventInfo(getApplicationContext(), "App Name", "Press here to resume", contentIntent);
        mNotificationManager.notify(1, notification);

This is with mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); already done in onCreate()

Really not sure what it is you're trying to do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top