2011-10-22 180 views
2

我在寫一些應用程序來訪問我的語音郵件。我有一個訪問號碼,當我打電話時,我必須等待6秒鐘,然後輸入我的PIN碼。 Android仍然沒有到sendDTMF的API,所以我必須在呼叫號碼中使用暫停。android代碼撥號暫停號碼

我搜索了互聯網,發現我可以輸入,(逗號)或p暫停一秒。但在Android模擬器上,這不起作用,例如,當使用逗號時,我撥打<access_number>,,,,,,<PIN_number>,,在模擬器上我只看到撥打了<access_number>。當使用p時,我看到訪問號碼和PIN級聯<access_number><PIN_number>

我該如何做一些暫停?

回答

0

曾在這裏同樣的問題,是我的解決方案(測試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(); 
    } 
}