將自己的應(yīng)用設(shè)置為系統(tǒng)默認(rèn)應(yīng)用婶溯,不考慮具體開發(fā)邏輯跌穗,首先要滿足一個(gè)條件是,你要告訴系統(tǒng)你具有處理這方面的能力菲嘴,而如何告訴系統(tǒng)呢饿自?
- 實(shí)現(xiàn)
InCallService
并注冊(cè)清單
@RequiresApi(Build.VERSION_CODES.M)
class MyPhoneCallService: InCallService() {
override fun onCallAdded(call: Call?) {
super.onCallAdded(call)
}
override fun onCallRemoved(call: Call?) {
super.onCallRemoved(call)
}
}
<service
android:name=".MyPhoneCallService"
android:permission="android.permission.BIND_INCALL_SERVICE">
<meta-data
android:name="android.telecom.IN_CALL_SERVICE_UI"
android:value="true" />
<intent-filter>
<action android:name="android.telecom.InCallService" />
</intent-filter>
</service>
- 實(shí)現(xiàn)電話接聽的UI
class FakeCallActivity:AppCompatActivity()
<activity android:name=".FakeCallActivity" >
<!-- provides ongoing call UI -->
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent-filter>
<!-- provides dial UI -->
<intent-filter>
<action android:name="android.intent.action.DIAL" />
</intent-filter>
</activity>
完成上述兩步,就可以在 應(yīng)用管理的默認(rèn)應(yīng)用 -> 撥號(hào) 選擇默認(rèn)應(yīng)用中看到自己的應(yīng)用了龄坪。
本文不涉及具體邏輯開發(fā)昭雌,僅用來(lái)記錄成為默認(rèn)撥號(hào)應(yīng)用,需要做的系統(tǒng)標(biāo)記健田。
具體實(shí)現(xiàn)邏輯烛卧,可以參考此鏈接安卓代替系統(tǒng)默認(rèn)電話應(yīng)用(Android 6.0+)與電話狀態(tài)監(jiān)聽