Intent.ACTION_DIAL 以#结尾的数字

Intent.ACTION_DIAL with number ending with #

所以我正在尝试通过 Intent.ACTION_DIAL 以 # 结尾发送一个号码,例如 *123#。但是当启动 Android 拨号器应用程序时,只有 *123(缺少#)。 我正在使用以下代码触发 Android.

的拨号应用程序
Uri number = Uri.parse("tel:*124#");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
context.startActivity(callIntent);

期待谢谢!! .

您需要对井号 (#) 进行正确编码。在您的 URL 请求中,它应该是 %23,所以用 %23 替换它就可以了。

Uri number = Uri.parse("tel:*124%23");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
context.startActivity(callIntent);

你也可以让URI做编码:

String encodedPhoneNumber = String.format("tel:%s", Uri.encode("*1234#"));
Uri number = Uri.parse(encodedPhoneNumber);
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
context.startActivity(callIntent);

答案可能与此有关link initiate a phone call on android with special character #
这条线可能是关键 Uri.parse("tel:"+Uri.encode("*124#"));