AlertDialog.Builder builder =new AlertDialog.Builder(mActivity);
builder.setMessage(“內(nèi)容”);// 設(shè)置內(nèi)容
builder.setTitle("聯(lián)系電話");// 設(shè)置標(biāo)題
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) {
//沒有授權(quán),編寫申請權(quán)限代碼
? ? ? ? ? ? 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));
? ? ? ? ? ? // 開啟系統(tǒng)撥號器
? ? ? ? ? ? startActivity(callintent);
? ? ? ? }
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {// 設(shè)置取消按鈕
? ? @Override
? ? public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
? ? }
});
// 參數(shù)都設(shè)置完成了,創(chuàng)建并顯示出來
builder.create();
builder.show();