Reputation: 1113
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();
Upvotes: 0
Views: 850
Reputation: 8641
However, the design pattern you're trying to implement is not preferred.
Android itself will notify the user of a missed call. The phone will vibrate, based on the user's settings for vibration.
If you want to, you can check the call log yourself whenever you receive an ACTION_PHONE_STATE_CHANGED, and based on it, you should send a notification. Displaying a dialog is an annoying approach that interrupts the normal flow of tasks. You can implement a content Intent for the notification that sends the user back to your app when the notification is clicked. Once in your application, the user can choose to turn off vibration.
A missed call is usually not something that should interrupt other work the user is doing.
Upvotes: 0
Reputation: 5203
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
Upvotes: 1