简体   繁体   English

对于 API > 29 和 API < 29 对于 Android 应用程序,我需要获取来电电话号码和该号码的通话记录的最低权限是多少?

[英]What are the minimum permissions I need to get incoming phone number and call history for that number for API > 29 and API < 29 for Android app?

I am looking to access the following functionalities for my Android App:我希望为我的 Android 应用程序访问以下功能:

  • DONE Detect states of incoming call (achieved via EXTRA_STATE, see below for more info) DONE检测来电状态(通过EXTRA_STATE实现,更多信息见下文)
  • Get incoming number (do not know how for API > 29, see below)获取来电号码(不知道API > 29如何,见下文)
  • Get history for the incoming number (this is optional since my app could build the phone history since I only need it for short term for this stage so I could technically build it in my app if I cannot easily access Missed/Answered call log for that number only.获取传入号码的历史记录(这是可选的,因为我的应用程序可以构建电话历史记录,因为我只需要在此阶段短期使用它,因此如果我无法轻松访问未接/已接听的通话记录,我可以在技术上在我的应用程序中构建它只有号码。

From research, I found that for older versions I could simply use通过研究,我发现对于旧版本,我可以简单地使用

intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER); intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

And I would get the number but it does not work for API > 29 (number comes out as null for API = 29 because it is deprecated in API level 29 .). And I would get the number but it does not work for API > 29 (number comes out as null for API = 29 because it is deprecated in API level 29 .). Also, I am not sure what is the easiest way to get the history for that number only.另外,我不确定仅获取该号码的历史记录的最简单方法是什么。

I could use inCallService and Google suggests to create the Default Phone App which could be then default call app and gives me all the required permissions.我可以使用inCallService并且 Google 建议创建默认电话应用程序,该应用程序可能是默认呼叫应用程序,并为我提供所有必需的权限。 However, my app does not need all those permissions and ideally it should not be a full blown call app, and it would be only a feature that would work on top of a default app therefore I am looking for alternative that would require the least amounts of permissions that Google would actually grant me.但是,我的应用程序不需要所有这些权限,理想情况下它不应该是一个完整的呼叫应用程序,它只是一个可以在默认应用程序之上运行的功能,因此我正在寻找需要最少数量的替代方案谷歌实际上会授予我的权限。

I also ask user for PHONE_CALL_STATE in order to get PHONE_STATE via EXTRA_STATE which only allows me to know when call started, ended, answered and missed.我还向用户询问 PHONE_CALL_STATE 以便通过 EXTRA_STATE 获取 PHONE_STATE,它只允许我知道呼叫何时开始、结束、接听和错过。 But I need a number itself and some history of missed/answered calls as well for different API's.但是我需要一个号码本身和一些未接/接听电话的历史记录以及不同的 API。

Any help will be greatly appreciated.任何帮助将不胜感激。

According to the docs , EXTRA_INCOMING_NUMBER is provided if the receiver app has the READ_CALL_LOG (in addition to the READ_PHONE_STATE permission).根据文档,如果接收方应用程序具有READ_CALL_LOG (除了READ_PHONE_STATE权限),则提供EXTRA_INCOMING_NUMBER

Once you add that READ_CALL_LOG, you'll notice your app will start receiving that broadcast twice , once with getString(EXTRA_INCOMING_NUMBER) returning null, and another with getString(EXTRA_INCOMING_NUMBER) containing the actual number.添加 READ_CALL_LOG 后,您会注意到您的应用程序将开始接收该广播两次,一次是getString(EXTRA_INCOMING_NUMBER)返回 null,另一次是getString(EXTRA_INCOMING_NUMBER)包含实际数字。 See docs note here . 请参阅此处的文档说明

Notes:笔记:

  • The order of the 2 broadcasts is not guaranteed, so if you get 2 broadcasts, where one has EXTRA_INCOMING_NUMBER = null, you can ignore that one.不能保证 2 个广播的顺序,所以如果你得到 2 个广播,其中一个有EXTRA_INCOMING_NUMBER = null,你可以忽略那个。
  • EXTRA_INCOMING_NUMBER is only received on incoming calls, there's no way to get the number of an outgoing call EXTRA_INCOMING_NUMBER仅在来电时收到,无法获取拨出电话的号码
  • That extra is indeed deprecated on API >= 29, but that only means your targetSdk (in your gradle file) should be < 29 for it to work.在 API >= 29 上确实不推荐使用该额外功能,但这仅意味着您的targetSdk (在您的 gradle 文件中)应该小于 29 才能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM