2014-05-19 32 views
0

我想打開代碼*#9900#的Dial Intent。但是電話應用程序總是顯示爲空。如何運行意向呼叫號碼*#9900#

這裏是我的代碼:

public void limpiarLogCat(View view) { 
    String encodedHash = Uri.encode("#"); 
    call("*" + encodedHash + "9900" + encodedHash); 
} 

protected void call(String phoneNumber) { 
     try { 
     startActivityForResult(
     new Intent("android.intent.action.DIAL", Uri.parse("tel:" 
          + phoneNumber)), 1); 
    } catch (Exception eExcept) { 

    } 
} 

而且,我在的manifest.xml宣佈android.permission.CALL_PHONE

你能幫我嗎?

回答

0

您不需要在清單中聲明撥號意圖過濾器,也不需要ACTION_DIAL的任何權限。尋找我的實現

private void startDialActivity(String phone){ 
    Intent intent = new Intent(Intent.ACTION_DIAL); 
    intent.setData(Uri.parse("tel:"+phone)); 
    startActivity(intent); 
} 

也很好,檢查支持設備上的電話

private boolean isTelephonyEnabled(){ 
    TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); 
    return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY 
} 

UPDATE: 嘗試使用

String encodedHash = Uri.encode("*9900#"); 
startDialActivity(encodedHash); 

,而不是

String encodedHash = Uri.encode("#"); 
startDialActivity("*" + encodedHash + "9900" + encodedHash); 
+0

謝謝Basbous,我已經在我的清單中聲明瞭這一點。但該方法不起作用。問候 – user3651769

+0

@ user3651769查看更新的答案 – Basbous

+0

謝謝Basbous,您的方法與Uri.encode(「* 9900#」)一起使用,但不適用於Uri.encode(「*#9900#」)。問候 – user3651769