AlertDialog(复制后直接用)
AlertDialog.Builder builder =new AlertDialog.Builder(mActivity);
builder.setMessage(“内容”);// 设置内容
builder.setTitle("联系电话");// 设置标题
builder.setPositiveButton("拨打", new DialogInterface.OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(DialogInterface dialog, int which) {
if (ContextCompat.checkSelfPermission(mActivity,
Manifest.permission.CALL_PHONE)
!= PackageManager.PERMISSION_GRANTED) {
//没有授权,编写申请权限代码
ActivityCompat.requestPermissions(mActivity, new String[]{Manifest.permission.CALL_PHONE}, 100);
}else {
// 打电话
Intent callintent =new Intent();
callintent.setAction(Intent.ACTION_CALL);
callintent.setData(Uri.parse("tel:" +phoneNumber));
// 开启系统拨号器
startActivity(callintent);
}
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {// 设置取消按钮
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
// 参数都设置完成了,创建并显示出来
builder.create();
builder.show();