malik M
malik M

Reputation: 333

I want to open a pop up on my main screen when user click on notification message

My application is sending a notification.I want to implement when a user check notification and click on the notification I want to open a pop up on my application main screen.It is some thing like that my main screen stay as it is but a pop up will open in front of it. Thanks In advance

Upvotes: 2

Views: 3525

Answers (4)

Ishank Gupta
Ishank Gupta

Reputation: 223

You will need a Broadcast a intent and a Intent Receiver

Below is my create Notification code. You will need to broadcast an intent when user clicks on notification icon.

    // create NotificationManager..
    NotificationManager mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = new Notification(R.drawable.icon, null,
            System.currentTimeMillis());

    // create intent that will be broadcast.
    Intent i = new Intent();
    i.setClassName(this, BReceiver.class.getName());    
    i.setAction("Test");

    PendingIntent contentIntent = PendingIntent.getBroadcast(this, 0, 
            i, 0);
    notification.setLatestEventInfo(this, null, null, contentIntent);
    mNotificationManager.notify(0, notification);

Below is my BroadCast Receiver

public class BReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        Log.d("Test", "########## intent action "+ intent.getAction());
        Toast.makeText(context, "Hi", Toast.LENGTH_LONG).show();

    }

}

The toast will be displayed when you click on the notification icon. It doesnot matter on which screen you are, the toast will be displayed whenever user click notification icon.

Upvotes: 2

varevarao
varevarao

Reputation: 2186

If you're basically asking about HOW to open the dialog (which I'm assuming you've created as an activity) upon clicking the notification, then check out the Notification docs regarding the addAction method in the Notification.Builder class. It allows you to launch any intent you specify upon clicking the notification.

Upvotes: 0

Sanket Kachhela
Sanket Kachhela

Reputation: 10856

put this

 android:theme="@android:style/Theme.Dialog"

in meanifeast for your target activity

Upvotes: 1

Sahil Mahajan Mj
Sahil Mahajan Mj

Reputation: 11141

Try using Alert Builder, Here is a snippet of code fir it,

new AlertDialog.Builder(this).
            setCancelable(false).
            setTitle("Title for popup").
            setMessage("Show Message here").
            setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    System.exit(0);
                }
            }).create().show();

Upvotes: 0

Related Questions