我正在编写一些应用程序来访问我的语音信箱。我有一个访问号码,当我拨打它时,我必须等待6秒钟,然后输入我的PIN码。 Android仍然没有sendDTMF的API,因此我必须在电话号码中使用暂停符。

我搜索了互联网,发现可以输入,(逗号)或p一秒钟。但是在Android模拟器上这是行不通的,例如,当使用逗号时,我拨打<access_number>,,,,,,<PIN_number>,,而在模拟器上我只看到拨打了<access_number>。使用p时,我看到访问号和PIN串连了<access_number><PIN_number>

我该如何停顿一下?

最佳答案

我的解决方案遇到了同样的问题(在Android4.0.1上测试):

    /**
 * Dials a number with DTMF chars
 * Note: When the number is dialed, only the initial number is displayed on the device dialer
 * For example: dial("*6900,,,3") will display only *6900 on the device dialer (but the rest will also be processed)
 * @param number
 */
public void dial(String number) {
    try {
        number = new String(number.trim().replace(" ", "%20").replace("&", "%26")
                .replace(",", "%2c").replace("(", "%28").replace(")", "%29")
                .replace("!", "%21").replace("=", "%3D").replace("<", "%3C")
                .replace(">", "%3E").replace("#", "%23").replace("$", "%24")
                .replace("'", "%27").replace("*", "%2A").replace("-", "%2D")
                .replace(".", "%2E").replace("/", "%2F").replace(":", "%3A")
                .replace(";", "%3B").replace("?", "%3F").replace("@", "%40")
                .replace("[", "%5B").replace("\\", "%5C").replace("]", "%5D")
                .replace("_", "%5F").replace("`", "%60").replace("{", "%7B")
                .replace("|", "%7C").replace("}", "%7D"));

        Uri uri = Uri.parse("tel:"+ Uri.encode(number));
        Intent intent = new Intent(Intent.ACTION_CALL, uri);
        startActivity(intent);

    } catch (Exception e) {
        //getAlertDialog().setMessage("Invalid number");
        e.printStackTrace();
    }
}

09-10 06:20
查看更多