Search code examples
androidalter

alertdialog when there is a missed call


alertdialog when there is a missed call I want to vibrate telephone when there is a missed call and display the dialogallert to stop the vibration

To use the dialog I'm using this code

 AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
                            alertDialog.setTitle("Call");
                            alertDialog.setMessage("show this?");

                            // "Yes" Button
                            alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,int which)
                               {

                                Toast.makeText(getApplicationContext(), "You clicked                        YES", Toast.LENGTH_SHORT).show();
                                }
                            });

                            //  "NO" Button
                            alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                // Write your code here to invoke NO event
                                Toast.makeText(getApplicationContext(), "You clicked NO", Toast.LENGTH_SHORT).show();
                                dialog.cancel();
                                }
                            });


                            alertDialog.show();

Solution

  • You can not get the Event/Broadcast/Notification for Missed Call but you can get events of ACTION_PHONE_STATE_CHANGED from keep a track of events in this order EXTRA_STATE_RINGING to EXTRA_STATE_OFFHOOK to EXTRA_STATE_IDLE

    After this you can check Call Log and find the Missed Call detail.

    For your connivance here is the code sample for fetching Call Log

    courtesy : AndDev.org