簡體   English   中英

截接號碼

[英]Intercepting number dialed

我不想成為默認的撥號器應用程序。

我只希望在用戶撥打默認撥號應用程序中的特定號碼(例如1234)時啟動我的應用程序。

這可能嗎?

場景:航空公司有一個應用程序可以進行預訂並提供許多客戶支持功能。 它還有一個客戶服務熱線。 但是,它希望減少熱線(昂貴的代理商)的訪問量,並希望盡可能多地看到該應用程序服務的大多數請求。 因此,當用戶撥打航空公司熱線號碼時,將啟動航空公司應用程序(如果已安裝)。

是的,有可能。 請從此處參考“收聽去電請求”。

在電話負載下運行您的應用。 這是在應用清單文件中聲明的廣播接收器示例:

<manifest>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />  
<application>
    ...
    <receiver android:name=MyOutgoingCallHandler">
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>
    ...
</application>
</manifest>

相應的廣播接收器的實現如下所示:

public class MyOutgoingCallHandler extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
    // Extract phone number reformatted by previous receivers
        String phoneNumber = getResultData();
        if (phoneNumber == null) {
        // No reformatted number, use the original
            phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        }
        // My app will bring up the call, so cancel the broadcast
        setResultData(null);
        // Start my app to bring up the call
    ...
  }
}

這樣您就可以從

phoneNumber

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM