[英]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 应用程序访问以下功能:
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:笔记:
EXTRA_INCOMING_NUMBER
= null, you can ignore that one.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
仅在来电时收到,无法获取拨出电话的号码targetSdk
(in your gradle file) should be < 29 for it to work.targetSdk
(在您的 gradle 文件中)应该小于 29 才能正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.