2014-03-13 49 views
27

我如何以編程方式從Android應用程序dial a number?我不想打一個電話,我知道我可以做一個意圖:new Intent(Intent.ACTION_CALL),我只想讓用戶進入Android撥號提示符,其號碼已經通過輸入,通過傳遞它的意圖,以便她可以選擇自己撥打該號碼。Android以編程方式撥打電話號碼

+1

同樣,鏈接描述如何進行一個電話,而不是如何撥打一個號碼。 –

回答

44

使用下面的代碼:

Uri number = Uri.parse("tel:123456789"); 
Intent callIntent = new Intent(Intent.ACTION_DIAL, number); 
startActivity(callIntent); 
+2

您可以使用此代碼爲您的活動提供輸入號碼,但您不能在@ user370305提供的答案中提供撥號號碼 –

+0

@fremmedehenvendelser這是與user370305提供的內容完全相關的片段。他提到在答案中加入數字,但在代碼中沒有這樣做。 –

+0

我使用相同的方法,但不在星系S7中工作。請提供任何建議? – AngelJanniee

8
Intent intent = new Intent(Intent.ACTION_CALL); 

intent.setData(Uri.parse("tel:" + bundle.getString("mobilePhone"))); 
context.startActivity(intent); 

不要忘了相關的許可添加到您的清單:

<uses-permission android:name="android.permission.CALL_PHONE" /> 
+1

我已經問過如何撥打*號碼,而不是如何打電話。 –

+0

雖然題外話,我很高興他發佈了這個答案。這正是我所尋找的 – Dwebtron

+0

我也是這幫了我。謝謝 –

10

使用ACTION_DIAL

一樣,

Intent intent = new Intent(Intent.ACTION_DIAL); 

活動事件:撥打一個號碼作爲指定由數據。這顯示了一個用戶正在撥打的號碼,允許用戶明確發起呼叫。

+0

謝謝,這麼簡單。 –

1

此代碼將使而無需用戶交互的呼叫,也將拿起默認的電話撥號

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + url)); 
    intent.setClassName("com.android.phone","com.android.phone.OutgoingCallBroadcaster"); 
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    startActivity(intent); 

如果你想要用戶選擇自己的撥號器刪除

intent.setClassName("com.android.phone","com.android.phone.OutgoingCallBroadcaster"); 

如果你只想把號碼扔給撥號器和你SER按下呼叫按鈕使用此代碼(我相信這就是你所要求的)

Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + url)); 
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    startActivity(intent); 

其中URL的電話號碼 並且不要忘了寫在清單文件的權限。

<uses-permission android:name="android.permission.CALL_PHONE" /> 
+0

請參閱Systematix Infotech的答案。 –

+0

呢? –

0

我具有通過

 btn.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v) { 
      String q=(t.getText().toString()); 
      Uri u=Uri.parse("tel:"+q); 

      Intent i=new Intent(Intent.ACTION_VIEW,u); 
      startActivity(i); 
     } 
    }); 
-1

此代碼解決會撥打您的電話號碼沒有手機默認調用鍵盤類似的問題:

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + textView.getText())); 
intent.setClassName("com.android.phone","com.android.phone.OutgoingCallBroadcaster"); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
startActivity(intent); 
相關問題