我试图通过点击一个按钮选择两个号码来直接拨打号码,但是当我选择其中一个号码时,它会转到拨号盘屏幕但是" Ljava。 lang.CharSequence"写在那里,弹出一个不支持消息服务的对话框。
这是我的代码: -
phone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final CharSequence numbers[] = new CharSequence[] {"02212345678","+14356789809"};
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Select number to call");
builder.setItems(numbers, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
String call = "tel:" +numbers;
callIntent.setData(Uri.parse(call));
startActivity(callIntent);
}
});
builder.show();
}
});
答案 0 :(得分:1)
更改
String call = "tel:" +numbers;
要
String call = "tel:" +numbers[which];
答案 1 :(得分:0)
phone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String number = "02212345678";
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Select number to call");
builder.setItems(number , new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
String call = "tel:" +number ;
callIntent.setData(Uri.parse(call));
startActivity(callIntent);
}
});
builder.show();
}
});
答案 2 :(得分:0)
这是一个完整的代码,用于选择数字并在按钮单击上调用所选的数字。我希望这也有助于其他成员。
phone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final CharSequence numbers[] = new CharSequence[] {"+1xxxxxxxxx","+1xxxxxxxxxx"};
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Select number to call");
builder.setItems(numbers, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
String call = "tel:" +numbers[which];
callIntent.setData(Uri.parse(call));
startActivity(callIntent);
// the user clicked on colors[which]
}
});
builder.show();
}
});