如何覆盖默认呼叫屏幕?
当用户从我的android应用中拨打任何号码而不是默认呼叫者屏幕时,我想启动我的自定义屏幕.
I want to launch my customized screen when user dials any number from my android app instead of default caller screen.
通常来说,为了知道如何覆盖任何默认的Activity,首先需要了解
Generally speaking, in order to know how to override any default Activity, first you need to know the structure of the Intent that can launch the Activity.
确定意图的结构
- 打开Android Monitor(又名Logcat)
- 过滤日志以仅显示与字符串"ActivityManager"匹配的内容
- 启动要覆盖的活动.您可以启动呼叫屏幕
如果可以覆盖活动",则应该看到带有"START ..."的日志条目,请复制该条目,以免在日志中丢失该条目.在我的设备上,该条目为:
If the Activity can be overridden, you should see a log entry with "START...", copy that entry so that you don't lose it in the log. On my device, this entry was:
START u0 {uid = android.intent.action.CALL dat = tel:xxxxxxxxxxx flg = 0x10000000 cmp = com.android.server.telecom/.CallActivity(有其他功能)}来自显示0的uid 10088
此意图由
- act-意图动作
- dat-目的数据
- cmp-目的组件
现在,您需要检查此Intent是否可以在不指定组件的情况下启动默认拨号程序.
Now you need to check if this Intent can launch the default dialer without specifying the component.
检查默认活动是否可以覆盖
- adb shell
- am start -a android.intent.action.CALL -d tel:xxxxxxxxxxx(填写您要测试的号码)
如果启动拨号程序,请瞧.您应该能够为您的应用程序创建一个IntentFilter ,动作和数据.然后,下一次用户尝试拨打电话时,它将询问用户他们想要使用哪个应用程序.
If it launches the dialer, then, voila. You should be able to create an IntentFilter for your application, setting the action and the data appropriately. Then, the next time the user tries to make a call, it will ask the user which app they want to use.