In my app i am doing one thing that,when the call is disconnected by caller or receiver,one alert dialog should appear with cellphone number.it all works fine but issue is alert dialog is also appearing when i am getting call,but i only want only after disconnection,i don't know what is mistake i am making following is my code..can any one help?
public class MyCallReceiver extends BroadcastReceiver {
private String incomingNumber;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_IDLE)) {
// This code will execute when the phone has an incoming call
// get the phone number
incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
Intent i = new Intent(context, Disp_Alert_dialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("Number", incomingNumber);
context.startActivity(i);
Toast.makeText(context, "Call from:" +incomingNumber, Toast.LENGTH_LONG).show();
/* String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast.makeText(context, "Call from:" +incomingNumber, Toast.LENGTH_LONG).show();*/
} else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_IDLE)
|| intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_OFFHOOK)) {
// This code will execute when the call is disconnected
}
}