只有在断开呼叫后才能获得警报对话框



我正在创建一个应用程序,我使用广播接收器来获取号码,我正在努力开发

1)当我接到电话和断开呼叫时,我能够在警报对话框中获得号码,它工作正常,但是当我从手机拨打电话时,问题是我然后断开连接,我也想获得带有号码的警报对话框,我不知道如何做到这一点以下是我的代码

问题是…我想在断开呼叫后打开警报对话框,无论是传入还是传出…

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

是的,因为incomingNumber只在来电时才会来。只有在通话结束后从通话记录中获取号码才能获得呼出号码

[如何为呼叫日志实现contenttobserver](如何为呼叫日志实现contenttobserver)

最新更新