HelloCW
HelloCW

Reputation: 2345

How can I display a warning information "missed call" in notification bar when I hang up a call programmatically in android?

Now I can hang up a call programmatically in android using the document Can I hang up a call programmatically in android?

Normally, a warning information "missed call ..." and a system icon will be displayed in notification bar when I miss a call.

But the warning information "missed call..." and a system icon won't be displayed when I invoke the function killCall(Context context). How can I make the warning information and the system icon to be displayed programmatically after I invoke the function killCall(Context context)?

And more, I hope the record of miss call can be displayed when I click the system icon.

enter image description here

Upvotes: 0

Views: 1190

Answers (1)

kodartcha
kodartcha

Reputation: 1073

Add this code just after you cancel the call:

NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, TheClassYouWantToOpenOnNotificationClick.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,  PendingIntent.FLAG_UPDATE_CURRENT);

Notification notification  = new Notification.Builder(IddleService.this)
                    .setContentTitle("Missed Call!")
                    .setContentText("Missed call from " +phoneNumber)
                    .setSmallIcon(R.drawable.your_icon)
                    .setContentIntent(pIntent)
                    .setAutoCancel(true).build();
nManager.notify(0, notification);

Where phoneNumber could be a string containing the number from the missed call.

Hope it helps :)

Upvotes: 2

Related Questions