AlertDialog(復(fù)制后直接用)

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();

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容