Android:为电信注册新的PhoneAccount [英] Android: register new PhoneAccount for telecom

查看:292
本文介绍了Android:为电信注册新的PhoneAccount的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个新的 PhoneAccount 以使用我的 ConnectionService 的实现.在文档中说我需要在TelecomManager中注册一个新的PhoneAccount,然后在我的电话应用程序的设置中选择它.

I'm trying to make a new PhoneAccount to use my implementation of ConnectionService. In the documentation it says I need to register a new PhoneAccount with TelecomManager and then select it in my phone-app's settings.

这是我的代码:

TelecomManager telecomManager = (TelecomManager) getSystemService(Context.TELECOM_SERVICE);

ComponentName componentName = newComponentName("se.example.connectionservicestandalonetest", "se.example.connectionservicestandalonetest.MyConnectionService");
PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(componentName, "Admin");
PhoneAccount phoneAccount = PhoneAccount.builder(phoneAccountHandle, "Admin").build();

telecomManager.registerPhoneAccount(phoneAccount);

如您所见,它将创建一个指向我的ConnectionService实现的新ComponentName,然后创建一个新的PhoneAccountHandle,在其中提供ComponentName和唯一的帐户名.然后,我在PhoneAccount版本中提供PhoneAccountHandle以及标签(名称?),以创建一个新的PhoneAccount.最后,我在telecomManager中注册了该帐户.

As you can see, it creates a new ComponentName that points towards my implementation of ConnectionService, then creates a new PhoneAccountHandle where I supply the ComponentName and a unique account-name. I then supply the PhoneAccountHandle in the PhoneAccount buildes, as well as label (a name?), to create a new PhoneAccount. Lastly I register the account in the telecomManager.

当我打开手机应用程序时,什么都没有改变.我看不到可以更改PhoneAccount的地方...有什么想法吗?

When I open up the phone app, nothing has changed. I see no where I could possibly change the PhoneAccount... Any ideas?

谢谢!

推荐答案

我已经得到一些信息,我将在这里留下来作为后代.

I've got some information that I'll just leave here for posterity.

构建PhoneAccount时,如果您自己拨打和接听电话,则必须添加CAPABILITY_CALL_PROVIDER;如果要使用内置PhoneAccount拨打或接听电话,则必须添加CAPABILITY_CONNECTION_MANAGER.没有任何一个,您将不会出现在用户界面中.

When building your PhoneAccount, you must add CAPABILITY_CALL_PROVIDER if you make and receive calls on your own, or CAPABILITY_CONNECTION_MANAGER if you want to make or receive calls using the builtin PhoneAccount. Without either, you won't show up in the UI.

据我所知,没有专用的API可以检查用户是否启用了PhoneAccount.但是,可以将TelecomManager.addNewIncomingCall用于此目的.只需提供一个包含布尔值额外内容的Bundle(命名为您想要的任何名称),然后在您确实收到呼叫时将该布尔值设置为true,或者如果您只是想进行权限检查,则将该布尔值设置为false ).然后,如果您只是在进行权限检查,则ConnectionService.onCreateIncomingConnection的实现可以检查您的额外内容并返回Connection.createCanceledConnection.这不会在通话记录中注册为通话,并且铃声永远不会播放.如果未启用PhoneAccount,则会抛出addNewIncomingCall;如果未启用,则会成功.

As far as I can tell, there is no dedicated API for checking whether the user has enabled your PhoneAccount. However, you can use TelecomManager.addNewIncomingCall for this purpose. Simply provide a Bundle containing a boolean extra (named whatever you want) and set that boolean to true if you're really receiving a call or false if you just want to do a permission check (or vice-versa). Then your implementation of ConnectionService.onCreateIncomingConnection can check your extra and return Connection.createCanceledConnection if you're just doing a permission check. This does not register as a call in the call log, and the ringtone never plays. addNewIncomingCall will throw if your PhoneAccount is not enabled, and succeed if it is.

如上面的注释所述,您可以提示用户使用TelecomManager.ACTION_CHANGE_PHONE_ACCOUNTS启用您的PhoneAccount.因为用户可以随时启用或禁用PhoneAccount,所以所有需要启用PhoneAccount的操作(如addNewIncomingCall)都应放在try块中.

As noted in the comments above, you can prompt the user to enable your PhoneAccount using TelecomManager.ACTION_CHANGE_PHONE_ACCOUNTS. Because the user can enable or disable your PhoneAccount at any time, all operations that require an enabled PhoneAccount (like addNewIncomingCall) should be placed in a try block.

这篇关于Android:为电信注册新的PhoneAccount的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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