我实现了清单中这样的CallService:
<service
android:name=".dialer.CallService"
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>
就是这样:
@TargetApi(Build.VERSION_CODES.M)
class CallService : InCallService() {
companion object {
private const val LOG_TAG = "CallService"
}
override fun onCallAdded(call: Call) {
super.onCallAdded(call)
App.GSMCALL = true;
Log.i(LOG_TAG, "onCallAdded: $call")
Log.i(LOG_TAG, "onCallAdded: ${call.details.handle.schemeSpecificPart}")
call.registerCallback(callCallback)
val intent = Intent(this, IncomingCallActivity::class.java)
if (call.details.handle.schemeSpecificPart.contains("<INSERT PHONE NR HERE>")) { // something similar will be done, if I don't pass new_task it will go through default caller
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivity(intent)
CallManager.updateCall(call)
}
override fun onCallRemoved(call: Call) {
super.onCallRemoved(call)
App.GSMCALL = false;
Log.i(LOG_TAG, "onCallRemoved: $call")
call.unregisterCallback(callCallback)
CallManager.updateCall(null)
}
private val callCallback = object : Call.Callback() {
override fun onStateChanged(call: Call, state: Int) {
Log.i(LOG_TAG, "Call.Callback onStateChanged: $call, state: $state")
CallManager.updateCall(call)
}
}
}
现在这就是我想要的。如果我的电话是,那么我希望它进行我的通话活动。 但是,如果它是一个不同的电话号码,我希望它回落到电话拨号程序中。这可能吗? 我已经看到,如果不添加FLAG_ACTIVITY_NEW_TASK,它将崩溃,从而使电话主Dialer出现。但这只能工作一次,而且我不会使用这种技巧来使其工作。还有其他想法吗?
答案 0 :(得分:0)
好吧,所以像在评论中一样,我建议侦听传入的呼叫事件,如果特定的呼叫正在进入,则将您的UI置于系统通话中UI之上。
收听来电: https://developer.android.com/reference/android/telephony/PhoneStateListener Add PhoneStateListener
显示始终位于顶部的视图: How to create always-top fullscreen overlay activity in Android