I am creating one app where I am using broadcast receiver to to get the number,I am trying to develop
1)while I am getting call and and disconnect call i am able to get number in alert dialog it works fine,but the issue when i make call from my cellphone and i then i disconnect i also want to get alert dialog with number,I do not know how to do that following is my code
Problem
Issue is..I want to open alert dialog only after disconnect call,either its is incoming or outgoing..
MyOutgoing.java
public class OutgoingCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_IDLE)) {
/* Bundle bundle = intent.getExtras();
if(null == bundle)
return;*/
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Intent i = new Intent(context, Disp_Alert_dialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("Number", phonenumber);
i.putExtra("type", "outgoing");
context.startActivity(i);
Log.i("OutgoingCallReceiver",phonenumber);
// Log.i("OutgoingCallReceiver",bundle.toString());
String info = "Outgoing number: " + phonenumber;
Toast.makeText(context, info, Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(context, "can you dig it suker", Toast.LENGTH_LONG).show();
}
}
}
MyIncoming.java
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_RINGING)) {
// get the phone number
incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Intent i = new Intent(context, Disp_Alert_dialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("Number", incomingNumber);
i.putExtra("type", "incoming");
context.startActivity(i);
// Toast.makeText(context, "Call from:" +incomingNumber, Toast.LENGTH_LONG).show();
// This code will execute when the phone has an incoming call
} else {
// This code will execute when the call is disconnected
// Toast.makeText(context, "Detected call hangup event", Toast.LENGTH_LONG).show();
}
}
}
Myalert
public class Disp_Alert_dialog extends Activity{
private String nums;
private String outnum;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent iin= getIntent();
nums=iin.getStringExtra("Number");
Intent iii=getIntent();
outnum=iii.getStringExtra("outNumber");
// Toast.makeText(Disp_Alert_dialog.this, "Got it"+nums, Toast.LENGTH_LONG).show();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
if(nums==iin.getStringExtra("Number"))
{
Toast.makeText(Disp_Alert_dialog.this, "eba andre incoming", Toast.LENGTH_LONG).show();
builder.setTitle(nums);
}
else if(outnum==iii.getStringExtra("outNumber"))
{
Toast.makeText(Disp_Alert_dialog.this, "eba ander outgoing", Toast.LENGTH_LONG).show();
builder.setTitle(outnum);
}
builder
.setMessage("Want to add in CRM?\n"
+ "If this call was New Inquiry,\n"
+ "Follow up or complaint call,\n"
+ "please add this in crm")
.setCancelable(false)
.setPositiveButton("Add to CRM", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
Intent intent=new Intent(Disp_Alert_dialog.this,MainMenu.class);
intent.putExtra("Nums", nums);
startActivity(intent);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}