我正在开发具有联系我们页面和电话号码的 Android 应用程序。我在 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"/>
我已经创建了 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;
}
}
我的问题是在onClick
“PositiveButton”方法中实现“调用电话号码”功能。请帮助我如何获得带有号码的拨号盘存在于带有 SampleCode/Links 的 xml
文件中。
最佳答案
也许是这样的:
Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:" + findViewByid(R.id.textView4).getText());
startActivity(call);
关于java - Activity中的Android电话号码调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8034823/