I am looking to access the following functionalities for my Android App:
From research, I found that for older versions I could simply use
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 .). 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. 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. But I need a number itself and some history of missed/answered calls as well for different API's.
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).
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. See docs note here .
Notes:
EXTRA_INCOMING_NUMBER
= null, you can ignore that one.EXTRA_INCOMING_NUMBER
is only received on incoming calls, there's no way to get the number of an outgoing call targetSdk
(in your gradle file) should be < 29 for it to work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.