简体   繁体   中英

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:

  • DONE Detect states of incoming call (achieved via EXTRA_STATE, see below for more info)
  • Get incoming number (do not know how for API > 29, see below)
  • 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);

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:

  • 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.
  • EXTRA_INCOMING_NUMBER is only received on incoming calls, there's no way to get the number of an outgoing call
  • 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.

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.

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