[英]Android Phone number Calling Function in an Activity
I am developing Android Application having ContactUs Page having Phone Number. 我正在开发具有电话号码的ContactUs页面的Android应用程序。 I had given the Phone number in xml file as below:
我在xml文件中给出了电话号码,如下所示:
<TextView
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="1-869-270-9099"
android:textSize="11sp"
android:textColor="#104082"
android:textStyle="normal"
android:layout_width="wrap_content"
android:id="@+id/textView4"
android:layout_x="72dp"
android:layout_y="160dp"/>
I had created the AlertDialog
and when the phone number is clicked the alert dialog
will be shown programatically as below: 我创建了
AlertDialog
,当单击电话号码时,将以编程方式显示警告dialog
,如下所示:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case (R.id.textView4):
Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Do you want to Call?");
builder.setCancelable(false);
builder.setPositiveButton("Call", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Do Calling a Number
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
return super.onCreateDialog(id);
}
public void onClick(View v) {
switch(v.getId()){
case (R.id.textView4):
showDialog(R.id.textView4);
break;
}
}
Here my issue is to implement the "Calling a Phone Number" Function in the onClick
"PositiveButton" method. 这里我的问题是在
onClick
“PositiveButton”方法中实现“调用电话号码”功能。 Please help me how to get a DialPad with the number present in the xml
file with the SampleCode/Links. 请帮我如何使用SampleCode / Links获取带有
xml
文件中存在的数字的DialPad。
Maybe something like: 也许是这样的:
Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:" + findViewByid(R.id.textView4).getText());
startActivity(call);
You can direclty launch a intent to get the dial pad with the number mentioned in your xml file.Like this: 你可以直接启动一个意图来获得带有xml文件中提到的数字的拨号盘。就像这样:
String contact=findViewById(R.id.textView4).getText().toString();
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + contact));
startActivity(callIntent);
Inside the onClick
of positive button
just write: 在正面
button
的onClick
里面写道:
Intent dial = new Intent();
dial.setAction("android.intent.action.DIAL");
dial.setData(Uri.parse("tel:"+dial_number));
startActivity(dial);
Note: Don't forget to add this permission inside the AndroidManifest.xml
file: 注意:不要忘记在
AndroidManifest.xml
文件中添加此权限:
<uses-permission android:name="android.permission.CALL_PHONE"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.