1

我的代码是:

    x="*141#"; 
    String phoneCallUri =("tel:" + x);
    Intent phoneCallIntent = new Intent(Intent.ACTION_DIAL);
    phoneCallIntent.setData(Uri.parse(phoneCallUri));
    startActivity(phoneCallIntent);

当调用电话功能时,它不使用#只调用* 141。请帮助我提前谢谢

4

2 回答 2

1

您应该将第二行更改为:String phoneCallUri = "tel:" + Uri.encode(x);

于 2013-07-22T11:51:42.037 回答
1

#在 Uri 中具有空间意义,因此您必须对其进行编码。像这样更正:

x="*141#"; 
String phoneCallUri =("tel:" + Uri.encode(x));
Intent phoneCallIntent = new Intent(Intent.ACTION_DIAL);
phoneCallIntent.setData(Uri.parse(phoneCallUri));
startActivity(phoneCallIntent);


编辑:
或更好的方法:

x="*141#";
Uri  uri = Uri.fromParts("tel", x, null);
Intent phoneCallIntent = new Intent(Intent.ACTION_DIAL);
phoneCallIntent.setData(uri);
startActivity(phoneCallIntent);
于 2013-07-22T11:51:53.353 回答