java - 如何为通话功能创建确认对话框

标签 java android xml dialog phone-call

我正在使用 Eclipse 进行 Android 应用程序开发,我想创建一个对话框,以便在从应用程序的按钮触发调用功能时进行确认。

例如,当我按下调用按钮时,我想要一个对话框,您确定要继续吗?是和否。

现在当我按下调用按钮时,它会直接自动拨号(没有拨号盘)

(我不确定这段代码是否对此负责)

public class AlertDialogManager {
/**
 * Function to display simple Alert Dialog
 * @param context - application context
 * @param title - alert dialog title
 * @param message - alert message
 * @param status - success/failure (used to set icon)
 *               - pass null if you don't want icon
 * */
public void showAlertDialog(Context context, String title, String message,
        Boolean status) {
    AlertDialog alertDialog = new AlertDialog.Builder(context).create();

    alertDialog.setTitle("Title");
    alertDialog.setMessage("Message");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
        }
    });

    // Showing Alert Message
    alertDialog.setIcon(R.drawable.icon);
    alertDialog.show();
}

}

最佳答案

如果您想在电话拨号中显示号码,只需执行以下操作Intent Intent = new Intent(Intent.ACTION_DIAL);

public class AlertDialogManager {
/**
 * Function to display simple Alert Dialog
 * @param context - application context
 * @param title - alert dialog title
 * @param message - alert message
 * @param status - success/failure (used to set icon)
 *               - pass null if you don't want icon
 * */
public void showAlertDialog(Context context, String title, String message,
        Boolean status) {
    AlertDialog alertDialog = new AlertDialog.Builder(context).create();

    alertDialog.setTitle("Title");
    alertDialog.setMessage("Message");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
          makeCall("12345");  //phone number you want to dial

        }
    });

    // Showing Alert Message
    alertDialog.setIcon(R.drawable.icon);
    alertDialog.show();
}

private void makeCall(String phone){
    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel:"+phone));
    startActivity(intent);
}

}

关于java - 如何为通话功能创建确认对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19279789/

相关文章:

java - Android webview录音不起作用

java - 在运行时将子报表添加到主报表(java)

java - 如何在constraintlayout中实现可滚动和放大缩小

c# - 如何在xml中返回GetResponseStream?

java - 从同一个 pojo 数组创建两个列表,修改一个列表,同样的事情也会影响其他列表

java - 如何从另一个类访问 JButton

android - 如何更新 PhoneGap 应用程序上的默认 IOS 图标?

android - 如何将媒体插入模拟器的SD卡......?

java - Flurry Agent 在 Android 2.3.4 上导致 CalledFromWrongThreadException 异常

java - org.simpleframework.xml.core.PersistenceException : Constructor not matched for class A