2014-01-27 30 views
0

我一直在嘗試這個箴言。當觸發與藍牙文件傳輸時,android手機必須自動打電話給一個給定的數字。可以在android中爲此編寫任何幫助。android編程,用於觸發電話

我需要從藍牙開始撥打電話的代碼,就像我從手機發送數據到手機時手機應該自動撥打一個預定義號碼一樣。

+0

那麼,你有什麼嘗試? – Swayam

+0

粘貼一些代碼! –

回答

0
String phone = "tel:" + "03242342342" ; 
Intent intent = new Intent(Intent.ACTION_CALL); 
intent.setData(Uri.parse(phone)); 
startActivity(intent); 

您需要爲此添加權限。

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

或更好的方法來使用

Intent.ACTION_DIAL

的意圖過濾器,以避免出現權限,ACTION_DIAL會選擇電話呼叫適當應用。

+0

我需要先檢測藍牙的數據傳輸,然後觸發呼叫,請你可以幫我解決這個問題。 – user3240144

0
public void call() { 
      Intent callIntent = new Intent(Intent.ACTION_CALL);   
      callIntent.setData(Uri.parse("tel:"+phone));   
      startActivity(callIntent); 
    } 

是一旦觸發傳輸時需要調用的函數。

+0

是的,但只有在數據傳輸完成後才能調用該函數,可以幫助我使用代碼 – user3240144

+0

該文檔清楚地說明了藍牙連接的不同回調。瀏覽它們:http://developer.android.com/guide/topics/connectivity/bluetooth.html。只要套接字完成從流中讀取數據,就將該調用發送到該函數。 – Swayam