我正在创建一个应用程序,我使用广播接收器来获取数字,我正在努力开发
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();
}
}
答案 0 :(得分:0)
是的,因为sWebChromeClient = new SampleWebChromeClient();
sWebView.setWebChromeClient(mWebChromeClient);
只会在来电时才会合作。
拨打电话号码的唯一方法是在通话结束后从通话记录中获取号码
[如何为通话记录实施ContentObserver](How to implement a ContentObserver for call logs)