Android - Prompt Dialog window when touch on Notif

2019-03-30 08:36发布

I am new to android application development. I am doing an application for my final year project.

My application will remind a user for an appointment. So far I manage to show the alert on notification bar on the appointment date.

My supervisor has requested to add a function, that, when a user tab on the notification bar, there will be a dialog window and show the details (Title of the appointment and the location).

How do I achieve this?

1条回答
甜甜的少女心
2楼-- · 2019-03-30 08:59

Try this:

Intent notifyIntent = new Intent(context,YourActivityClassHere.class);
notifyIntent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
//UNIQUE_ID if you expect more than one notification to appear
PendingIntent intent = PendingIntent.getActivity(SimpleNotification.this, UNIQUE_ID, 
            notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);

just make the PendingIntent open up one of your Activities and have your Activity be complete transparent and just open a Dialog.

EDIT: IF you want to open an Activity from notification click event:

Assuming that notif is your Notification object:

Intent notificationIntent = new Intent(this.getApplicationContext(), ActivityToStart.class);
PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0);
notif.contentIntent = contentIntent;

For other assistance you can view this sample project, it will help you:

查看更多
登录 后发表回答