Android and incoming call

How to detect incoming calls, in an Android device?

I’m trying to make an app like, when a call comes to the phone I want to detect the number. Below is what I tried, but it’s not detecting incoming calls.

I want to run my MainActivity in background, how can I do that?

I had given the permission in manifest file.

Is there anything else should I provide in the manifest?

11 Answers 11

Here’s what I use to do this:

My base reusable call detector

Then to use it, simply derive a class from it and implement a few easy functions, whichever call types you care about:

In addition you can see a writeup I did on why the code is like it is on my blog. Gist link: https://gist.github.com/ftvs/e61ccb039f511eb288ee

EDIT: Updated to simpler code, as I’ve reworked the class for my own use

and to unregister

Restricted access to call logs

Android P moves the CALL_LOG , READ_CALL_LOG , WRITE_CALL_LOG , and PROCESS_OUTGOING_CALLS permissions from the PHONE permission group to the new CALL_LOG permission group. This group gives users better control and visibility to apps that need access to sensitive information about phone calls, such as reading phone call records and identifying phone numbers.

To read numbers from the PHONE_STATE intent action, you need both the READ_CALL_LOG permission and the READ_PHONE_STATE permission. To read numbers from onCallStateChanged() , you now need the READ_CALL_LOG permission only. You no longer need the READ_PHONE_STATE permission.

Источник

Читайте также:  Android intent action main что это
Оцените статью