使用android.telecom和InCallService接听来电 [英] Answer incoming call using android.telecom and InCallService

查看:111
本文介绍了使用android.telecom和InCallService接听来电的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从API 21开始,Google一直在 TelecomManager上的TelecomManager ,并添加了

Since API 21, Google has been adding features to android.telecom in general, especially by implementing more members of TelecomManager and the addition of InCallService. This last one is is supposed to allow non-system, 3rd-party apps to provide and replace the functionality of the system Calls app in-call screen - the Window that pops up and allows action on EXTRA_STATE_OFFHOOK or EXTRA_STATE_RINGING broadcasts (i.e. incoming and outgoing phone calls).

当前,仅此屏幕通过root限制的MODIFY_PHONE_STATE权限和许多安全的AOSP代码(甚至不能通过反射访问)完全控制振铃和活动呼叫以及具有细粒度信息的相关系统回调.值得注意的是,这是不同制造商ROM风格中变化最大的代码之一,以及启动器,联系人和相机.

Currently, only this screen has full control of ringing and active calls and associated system callbacks with fine-grained information, by means of the root-restricted MODIFY_PHONE_STATE permission and a lot of secured AOSP code not even accessible by reflection. It's notably one of the most changed pieces of code in different manufacturers' ROM flavours, together with the launcher, contacts and camera.

这一切都很漂亮,但是...

This is all very pretty but...

您实际上如何开发第三方InCallService?

即:

  1. 如何获得有关GSM呼叫的通知并获取实例
  2. 一个人如何接听这些电话
  3. 此类的回调的生命周期是什么
  4. Google是否提供了我没有找到的任何实际教程

我不会一次提出所有这些问题的答案,但是任何一个答案都可能与其他问题相关.这是广泛的,但从本质上讲,它必须是:除了AOSP代码以外,我在网上找不到其他示例,并且该代码基于对root特权的假设,这使其无法用于第三方应用程序开发目的.

I won't ask answers for all of these at once, but any one answer probably associates to the other questions. This is broad but intrinsically it needs to be: there's no example on the web I've stumbled upon other than AOSP-code, and that code is based on the assumption of root-privileges, which makes it unusable for 3rd-party app development purposes.

推荐答案

如何获取有关GSM呼叫的通知并获取实例

首先,用户将需要选择您的应用程序作为默认的电话"应用程序.请参阅使用InCallService替换Android 6和7上的默认Phone应用,以实现此目的.

How do you get notified about, and acquire instances of GSM Calls

First, the user will need to select your app as the default Phone app. Refer to Replacing default Phone app on Android 6 and 7 with InCallService for a way to do that.

您还需要定义 InCallService 实现系统将绑定并通知您有关呼叫的信息:

You also need to define an InCallService implementation the system will bind to and notify you about the call:

<service
    android:name=".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>

您应该至少处理 onCallAdded (在Call上设置侦听器,启动您的UI-活动-进行通话)和

There you should handle at least onCallAdded (set up listeners on Call, start your UI - activity - for the call) and onCallRemoved (remove listeners).

如果用户想接听电话,则需要调用方法 Call#answer(int) VideoProfile.STATE_AUDIO_ONLY .

If the user wants to answer the call, you need to invoke the method Call#answer(int) with VideoProfile.STATE_AUDIO_ONLY for example.

查看 Call.Callback 一个电话就能发生.

Check out Call.Callback for events that can happen with a single call.

我不了解Google,但是您可以查看我的简化示例 https://github .com/arekolek/simple-phone

I don't know about Google, but you can check out my simplified example https://github.com/arekolek/simple-phone

这篇关于使用android.telecom和InCallService接听来电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆