Reputation: 55
I already built push notification by using Firebase Cloud Messaging on Eclipse Project. Now I want to make dialog with OK button when I touch the notification on status bar.
Can anyone help me? or suggest how to handle it? FYI, anytime (when the apps on background or in foreground) if I touch the notification on top it will show a dialog box.
Many thanks.
Upvotes: 1
Views: 1899
Reputation: 282
Firstly you need to use a pending intent with your notification that defines how to handle the notification click.
Intent notificationIntent = new Intent(this, DialogActivity.class);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new Notification.Builder(this)
// YOUR Notification parameters
.build();
notification.contentIntent = pendingNotificationIntent;
See that the intent points to a DialogActivity, so we need to create a DialogActivity to handle the intent. See the code below :
public class DailogActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Get Extra data from intent if you pass something
// Intent intent = getIntent();
// Bundle extras = intent.getExtras();
// Show the popup dialog
showNewDialog(0);
}
public void showNewDialog(int id) {
// TODO : Code to show the new dialog
}
}
Upvotes: 1