我有一个看起来像这样的intent过滤器:
<activity
android:name="com.test.Call"
android:label="@string/makeCall" >
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<data android:scheme="tel" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
这很好用,当你尝试拨打电话时,我的文字显示为其中一个选项.我想要做的是处理被呼叫的号码并询问用户一些问题,然后继续通话.我通过在执行任何处理之后运行以下代码来执行此操作:
Uri phoneCall = Uri.parse("tel:" + numToCall);
Intent caller = new Intent(Intent.ACTION_DIAL, phoneCall);
startActivity(caller);
Run Code Online (Sandbox Code Playgroud)
问题是,它从头开始显示相同的选项(本机调用者和我的意图过滤器).这不是我想要的,我想绕过我的意图过滤器并直接转到本机调用者.有没有办法做到这一点?如何强制意图直接转到本地调用者?我正在考虑将其移动到广播接收器,但宁愿走这条路.
谢谢
您可以尝试通过 PackageManager.setComponentEnabledSetting() 禁用组件[使用 DONT_KILL_APP 标志!],但您需要在下次调用之前再次重新启用该组件。
或者,您可以采纳上面黄的评论,但找出捕获 ACTION_CALL 意图的组件,并构建您自己的选择器(如果有多个组件) - 使用 PackageManager.queryIntentActivities() 获取活动列表。
使用广播确实是正确的方法。
| 归档时间: |
|
| 查看次数: |
8349 次 |
| 最近记录: |