如何在Android应用程序中以编程方式拨打号码?我不想直接拨打电话,因为我知道可以通过创建一个意图:new Intent(Intent.ACTION_CALL)
来实现。我只是想通过传递号码到意图中,使用户能够进入Android拨号提示界面,并将号码预先输入,以便她有选择是否拨打该号码的选项。
如何在Android应用程序中以编程方式拨打号码?我不想直接拨打电话,因为我知道可以通过创建一个意图:new Intent(Intent.ACTION_CALL)
来实现。我只是想通过传递号码到意图中,使用户能够进入Android拨号提示界面,并将号码预先输入,以便她有选择是否拨打该号码的选项。
使用以下代码:
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
startActivity(callIntent);
例如,
Intent intent = new Intent(Intent.ACTION_DIAL);
Activity Action: 根据数据指定的号码拨打电话。这将显示一个UI界面并拨出指定的号码,允许用户明确地发起呼叫。
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + bundle.getString("mobilePhone")));
context.startActivity(intent);
不要忘记在您的清单文件中添加相关权限:
<uses-permission android:name="android.permission.CALL_PHONE" />
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + url));
intent.setClassName("com.android.phone","com.android.phone.OutgoingCallBroadcaster");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
intent.setClassName("com.android.phone","com.android.phone.OutgoingCallBroadcaster");
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + url));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
其中url是电话号码,不要忘记在清单文件中写入权限。
<uses-permission android:name="android.permission.CALL_PHONE" />
我曾经遇到过类似的问题,后来解决了。
btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
String q=(t.getText().toString());
Uri u=Uri.parse("tel:"+q);
Intent i=new Intent(Intent.ACTION_VIEW,u);
startActivity(i);
}
});
这段代码将在没有手机默认拨号键盘的情况下拨打您的号码:
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + textView.getText()));
intent.setClassName("com.android.phone","com.android.phone.OutgoingCallBroadcaster");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);