1

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();
}

 }
jimmy
  • 91
  • 1
  • 1
  • 9
  • may be query the call log contentprovider. – Jiang YD Jun 05 '15 at 05:32
  • sorry i dint get you..my question is simple i jst want to get incoming and outgoing call number in alert dialog... – jimmy Jun 05 '15 at 05:38
  • http://www.programcreek.com/java-api-examples/index.php?api=android.provider.CallLog – Jiang YD Jun 05 '15 at 05:43
  • i dont want callhistory..i said i want number in alert dialog after disconnect either i am making a call and disconnect or i am receiving call and disconnect..now you get?? – jimmy Jun 05 '15 at 05:57
  • Look [here](http://stackoverflow.com/questions/4490403/is-it-possbile-to-detect-rejected-calls-in-android) maybe it will help you out – Strider Jun 05 '15 at 06:35
  • calllog have the number you want man – Jiang YD Jun 05 '15 at 06:47
  • try to follow my code..you will get number in alert dialog when you getting call and disconnect,,but you never get number when you call someone and then disconnect.. – jimmy Jun 05 '15 at 06:57
  • Yes because `incomingNumber` will only cone when call is incoming. Only way to get number in outgoing call is to get it from call log after call is over – Rishabh Singh Bisht Jun 05 '15 at 09:46

1 Answers1

0

Yes because incomingNumber will only coMe when call is incoming. Only way to get number in outgoing call is to get it from call log after call is over

[How to implement a ContentObserver for call logs] (How to implement a ContentObserver for call logs)

Community
  • 1
  • 1