0

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

Community
  • 1
  • 1
HelloCW
  • 843
  • 22
  • 125
  • 310

1 Answers1

2

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 :)

ColdFire
  • 6,764
  • 6
  • 35
  • 51
kodartcha
  • 1,063
  • 12
  • 23
  • Thanks! But I hope mobile phone can display a system warning icon when you miss a call. just like https://www.dropbox.com/s/q54do3773xup8ih/misscall.PNG – HelloCW Apr 22 '14 at 14:25
  • with `.setSmallIcon(R.drawable.your_icon)` you can set any icon you want. Search for the one in the link, copy it to your drawables folder and done. You could use this icon: http://m1.behance.net/rendition/modules/24789809/disp/e3b420f87b09d2c4857d43f93e664ccb.png Or check for the icons provided by Android. For sure you will find it there. http://developer.android.com/downloads/design/Android_Design_Icons_20131106.zip – kodartcha Apr 22 '14 at 14:28
  • Thanks! How can I display the default icon of miss call? – HelloCW Apr 22 '14 at 14:32
  • This one: `.setSmallIcon(android.R.drawable.sym_call_missed)` – kodartcha Apr 22 '14 at 14:35
  • Thanks! how can I display the missing call records when I click the icon? – HelloCW Apr 23 '14 at 00:12
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/51284/discussion-between-hellocw-and-margabro) – HelloCW Apr 23 '14 at 14:23