[我使用此代码显示数字,并在按下数字进行拨号时使用。它适用于Android Pie之前的android版本。
final Button but= findViewById(R.id.buttond);
but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String PhNumber = "6998474783";////example number
final CharSequence[] phones = PhNumber.split(" - ");
AlertDialog.Builder builder = new AlertDialog.Builder(CTX);
builder.setTitle("Επιλογή Τηλεφώνου");
builder.setItems(phones, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Do something with the selection
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phones[item].toString()));
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return; }
startActivity(intent);
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
要与Pie及以上版本一起使用,我需要更改什么?它显示了电话号码,但是当我按时,什么也没有发生
使用ACTION_DIAL解决,没有任何checkSelfPermission。
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phones[item].toString()));
startActivity(intent);
[如果还有其他方法,请与电信管理器一起发布。