单击按钮打开拨号盘,此字符串例如String str =" *#06#"应该用拨号盘打开。?

时间:2017-05-17 14:12:59

标签: java buttonclick

我的代码是这样的:

public void onclickdial(View v) {
String str = "*#06#";
startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+str)));
Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT).show(); }

但是只有问题*拨号屏幕上会显示*符号:

enter image description here

1 个答案:

答案 0 :(得分:1)

        String str = "*#06#";
    Intent callIntent = new Intent(Intent.ACTION_DIAL);
    callIntent.setData(Uri.fromParts("tel", str, ","));
    Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT).show();
    startActivity(callIntent);

或:

        String str = "*#06#";
    startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+ Uri.encode(str))));
    Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT).show();