使用InCallService替换Android 6和7上的默认Phone应用

han*_*ola 5 android android-intent android-6.0-marshmallow android-7.0-nougat android-7.1-nougat

添加InCallService了Android API级别23,以提供用于管理电话的用户界面。该文档提供了清单注册示例,但我无法使它正常工作。该应用可以正常编译,但设置中的默认应用不会显示我的应用。

我发现有关该主题的任何信息的唯一地方是年前关闭的StackOverflow问题。对提出增加android.intent.action.DIAL活动的那个问题发表评论,但这也无济于事。我在活动中也尝试了其他其他意图的组合(android.intent.action.CALL_DIALandroid.intent.action.ANSWER)。

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

are*_*lek 5

该应用可以正常编译,但设置中的默认应用不会显示我的应用。

要将您的应用程序列为“电话”应用程序,您必须具有至少包含这些意图过滤器的活动(以处理ACTION_DIAL文档中提到的两种情况,DefaultDialerManager隐藏类中也提到过):

<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>
Run Code Online (Sandbox Code Playgroud)

老实说,这有点违反直觉,因为设置默认的Phone应用程序与设置默认的Dialer是分开的-前者仅控制正在进行的呼叫UI,而后者仅控制拨号UI。

可以将上述最小值进行一些改进,以允许将拨号程序设置为默认值,并通过使用以下意图过滤器从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>
Run Code Online (Sandbox Code Playgroud)

AOSP中Dialer应用程序具有更多已声明的过滤器。

在以下方面的帮助下,您可以使用户更轻松地将您的应用设置为默认的“电话”应用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)
}
Run Code Online (Sandbox Code Playgroud)

这将显示类似于以下的对话框:

更改默认拨号对话框

请参阅使用android.telecom和InCallService接听来电,以实际处理呼叫本身所需执行的操作。

以下是应用程序的代码,该代码实现了在其自己的UI中处理拨号以及接受/拒绝/结束呼叫所需的最低要求:

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