2014-03-13 28 views
2

我有一個應用程序調用的電話呼叫的API, 當用戶撥打從Android手機的默認撥號器一個數字,這個數字應該被複制到第二應用(免費電話twilio),如圖所示。從Android默認撥號器發送一個手機號碼給我的應用程序

enter image description here

這裏是我的嘗試,但沒有運氣。

<activity 
android:name=".MainActivity" 
android:screenOrientation="portrait" 
android:theme="@android:style/Theme.NoTitleBar" > 
<intent-filter> 
<action android:name="android.intent.action.CALL_BUTTON" /> 

<category android:name="android.intent.category.DEFAULT" /> 
</intent-filter> 
<intent-filter> 
<action android:name="android.intent.action.CALL_PRIVILEGED" /> 
<category android:name="android.intent.category.DEFAULT" /> 
<data android:scheme="tel" /> 
</intent-filter> 
</activity> 

任何人都可以幫忙嗎? :-)

回答

0

它可以在谷歌搜索了很多之後纔有可能。最後,我得到了一個答案,我正在爲其他人分享。

它可以通過添加以下清單文件意圖過濾是可能的。

<intent-filter> 
     <action android:name="android.intent.action.CALL_BUTTON" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
-1

用android.intent.action.NEW_OUTGOING_CALL創建一個廣播接收器,然後調用 dialledNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

這會給你呼出號碼

嘗試this.it可能有助於

Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber)); 
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
context.startActivity(callIntent); 
+0

我想從我的應用程序撥打電話。您的建議答案是用SIM卡撥打電話後的讀取號碼。 – Amy

+0

我想你應該打電話給你打電話的默認應用程序。 –

+0

是的,我打電話給我的應用程序,但不能能夠撥打的號碼傳遞給應用程序 – Amy

0

,請使用以下代碼

註冊一個BroadcastReceiver這樣的清單文件:

<!-- DIAL Receiver --> 
    <receiver 
     android:exported="true" 
     android:name="receivers.DialBroadcastReceiver" > 
     <intent-filter > 
      <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> 
     </intent-filter> 
    </receiver> 

您需要獲得NEW_OUTGOING_CALL的許可:

<!-- OUTGOING CALL PERMISSION--> 
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> 

public class DialBroadcastReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 

    Log.v("DileBroadCastReceiver","In onReceive()"); 

    if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) { 
     String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 

     Log.v("DialBroadcast Receiver","Number is: "+number); 

    } 

    } 
} 
+0

SANKET我要撥打的號碼傳遞給對myApp選擇我的應用 – Amy

+0

後是,你可以進入這個Log.v(「DialBroadcast Receiver」,「Number is:」+ number); –

+0

廣播接收器在開始通話後執行。我想通過VoIp API從MyApp撥打電話(如Skype) – Amy

0

我想你忘了添加意圖過濾器在你的mainActivty像下面

 <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

還可以添加你現有的意向篩選器。 GUD運氣

相關問題