android - 使用 InCallService 替换 Android 6 和 7 上的默认电话应用程序

标签 android android-intent android-6.0-marshmallow android-7.0-nougat android-7.1-nougat

添加了 Android API 级别 23 InCallService 提供用于管理电话调用的用户界面。该文档提供了一个示例 list 注册,但我无法让它工作。该应用程序编译正常,但设置中的默认应用程序未显示我的应用程序。

我唯一找到有关该主题的信息的地方是 a StackOverflow question那是一年前关闭的。对建议添加 android.intent.action.DIAL Activity 的问题发表评论,但这对我也没有帮助。在我的 Activity 中,我也尝试了其他 Intent 的各种组合(android.intent.action.CALL_DIALandroid.intent.action.ANSWER)。

是否有替换手机应用程序所需的代码示例?这些类是否需要提供一些工作方法供应用程序显示?

最佳答案

The app compiles fine but Default Apps in settings doesn't show my app.

要将您的应用列为电话应用,您的 Activity 必须至少包含这些 Intent 过滤器(以处理 ACTION_DIAL 文档中提到的两种情况,也在 DefaultDialerManager hidden class 中提到):

<intent-filter>
    <action android:name="android.intent.action.DIAL" />
    <data android:scheme="tel" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.DIAL" />
</intent-filter>

老实说,这有点违反直觉,因为设置默认电话应用与设置默认拨号器是分开的——前者仅控制正在进行的通话 UI,而后者仅控制拨号 UI。

上面的最小值可以稍微改进,允许将拨号器设置为默认值,并通过使用这些 Intent 过滤器从 Web 浏览器启动:

<intent-filter>
    <!-- Handle links from other applications -->
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.DIAL" />
    <!-- Populate the system chooser -->
    <category android:name="android.intent.category.DEFAULT" />
    <!-- Handle links in browsers -->
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="tel" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.DIAL" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Dialer app in AOSP声明了更多过滤器。

TelecomManager 的帮助下,您可以让用户更轻松地将您的应用设置为默认电话应用:

if (getSystemService(TelecomManager::class.java).defaultDialerPackage != packageName) {
    Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
            .putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, packageName)
            .let(::startActivity)
}

这将显示一个类似于此的对话框:

change default dialer dialog

引用Answer incoming call using android.telecom and InCallService了解您需要做些什么才能真正自己处理调用。

这是一个应用程序的代码,它实现了在其自己的 UI 中处理拨号和接听/拒绝/结束调用所需的最低限度:

https://github.com/arekolek/simple-phone

关于android - 使用 InCallService 替换 Android 6 和 7 上的默认电话应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42838222/

相关文章:

java - 如何在一个字符串中存储多个单词而不替换java中的旧单词

android - android中调用结束过程的 Action 事件

java - Android Marshmallow 中的 SimpleDateFormat 行为更改

Android FCM 无法在 channel "my_channel_01"上发布通知

android - Realm.io - 是否可以通过其子对象找到对象?

java - 在某些设备上不会调用 Camera onPreviewFrame()(不存在预览显示)

android - 输入文本时如何抑制字典提示?

android - 是否可以从广播接收器启动 Intent ?

android - Cordova:无法使用 cordova-plugin-calendar 构建项目

android - Appcelerator Studio - 当我在视频播放器中加载 URL 时,Android 应用程序在 Marshmallow 上崩溃