Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Detecting an incoming call coming to an Android device. Remember to set the appropriate permissions in AndroidManifest.xml as suggested in the Stackoverflow link. Usage example in comments. Source: Gabe Sechan http://stackoverflow.com/a/15564021/264619 Explanation: http://gabesechansoftware.com/is-the-phone-ringing/#more-8
package com.gabesechan.android.reusable.receivers;
import java.util.Date;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public abstract class PhonecallReceiver extends BroadcastReceiver {
//The receiver will be recreated whenever android feels like it. We need a static variable to remember data between instantiations
private static int lastState = TelephonyManager.CALL_STATE_IDLE;
private static Date callStartTime;
private static boolean isIncoming;
private static String savedNumber; //because the passed incoming is only valid in ringing
@Override
public void onReceive(Context context, Intent intent) {
//We listen to two intents. The new outgoing call only tells us of an outgoing call. We use it to get the number.
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
}
else{
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
int state = 0;
if(stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)){
state = TelephonyManager.CALL_STATE_IDLE;
}
else if(stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
state = TelephonyManager.CALL_STATE_OFFHOOK;
}
else if(stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)){
state = TelephonyManager.CALL_STATE_RINGING;
}
onCallStateChanged(context, state, number);
}
}
//Derived classes should override these to respond to specific events of interest
protected void onIncomingCallStarted(Context ctx, String number, Date start){}
protected void onOutgoingCallStarted(Context ctx, String number, Date start){}
protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end){}
protected void onOutgoingCallEnded(Context ctx, String number, Date start, Date end){}
protected void onMissedCall(Context ctx, String number, Date start){}
//Deals with actual events
//Incoming call- goes from IDLE to RINGING when it rings, to OFFHOOK when it's answered, to IDLE when its hung up
//Outgoing call- goes from IDLE to OFFHOOK when it dials out, to IDLE when hung up
public void onCallStateChanged(Context context, int state, String number) {
if(lastState == state){
//No change, debounce extras
return;
}
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
isIncoming = true;
callStartTime = new Date();
savedNumber = number;
onIncomingCallStarted(context, number, callStartTime);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//Transition of ringing->offhook are pickups of incoming calls. Nothing done on them
if(lastState != TelephonyManager.CALL_STATE_RINGING){
isIncoming = false;
callStartTime = new Date();
onOutgoingCallStarted(context, savedNumber, callStartTime);
}
break;
case TelephonyManager.CALL_STATE_IDLE:
//Went to idle- this is the end of a call. What type depends on previous state(s)
if(lastState == TelephonyManager.CALL_STATE_RINGING){
//Ring but no pickup- a miss
onMissedCall(context, savedNumber, callStartTime);
}
else if(isIncoming){
onIncomingCallEnded(context, savedNumber, callStartTime, new Date());
}
else{
onOutgoingCallEnded(context, savedNumber, callStartTime, new Date());
}
break;
}
lastState = state;
}
}
@ftvs

This comment has been minimized.

Copy link
Owner Author

@ftvs ftvs commented Aug 5, 2015

Add the following to AndroidManifest.xml

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

<!--This part is inside the application-->
    <receiver android:name=".CallReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
    </receiver>

Usage example:

public class CallReceiver extends PhonecallReceiver {

    @Override
    protected void onIncomingCallStarted(Context ctx, String number, Date start) {
    }

    @Override
    protected void onOutgoingCallStarted(Context ctx, String number, Date start) {
    }

    @Override
    protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end) {
    }

    @Override
    protected void onOutgoingCallEnded(Context ctx, String number, Date start, Date end) {
    }

    @Override
    protected void onMissedCall(Context ctx, String number, Date start) {
    }

}
@ftvs

This comment has been minimized.

Copy link
Owner Author

@ftvs ftvs commented Aug 5, 2015

Note that I am not the author of the code.

@meness

This comment has been minimized.

Copy link

@meness meness commented Nov 19, 2015

Awesome, it works like a charm, thanks.

@juansebahler

This comment has been minimized.

Copy link

@juansebahler juansebahler commented May 11, 2016

Hi ftvs

Your code works great!

Thank you very much!

@thucvn

This comment has been minimized.

Copy link

@thucvn thucvn commented Jun 10, 2016

nice :D

@anand-sonawane

This comment has been minimized.

Copy link

@anand-sonawane anand-sonawane commented Jul 11, 2016

How to use it in the activity ? Means say i want to write the number and the duration to my layout screen in the app, how do i do that ?

@BlancGuillaume

This comment has been minimized.

Copy link

@BlancGuillaume BlancGuillaume commented Jul 27, 2016

Hi, I have the same question than anand-sonawane.
MyActivity already extends Activity and the multiple heritage isn't allowed ...
It's probably a stupid question ... Sorry for that, i'm a beginner

@youneszeboudj

This comment has been minimized.

Copy link

@youneszeboudj youneszeboudj commented Oct 9, 2016

there is a problem with the receiver it pass the wrong number to the 'PhonecallReceiver' methods:
for example if i call 222 and the call does not work out (because of network error for example), the next time if i call 112 and the call works it is not "112" that is passed but "222" i think because you pass the savedNumber field which contains the previous number (222).

@CeccoCQ

This comment has been minimized.

Copy link

@CeccoCQ CeccoCQ commented Oct 11, 2016

Not works for me.

@sameer9126

This comment has been minimized.

Copy link

@sameer9126 sameer9126 commented Nov 14, 2016

Awesome ... it's working good.

@nguyenlehuy84

This comment has been minimized.

Copy link

@nguyenlehuy84 nguyenlehuy84 commented Dec 7, 2016

It works ok on simulator. But I have same problem with youzking when I deployed to real device. First time I got null, second time I got first time number and so on ...

@sathishmscict

This comment has been minimized.

Copy link

@sathishmscict sathishmscict commented Dec 15, 2016

it's working perfect....

@marouaneterai

This comment has been minimized.

Copy link

@marouaneterai marouaneterai commented Dec 15, 2016

Hello guys,
i need to know how to use this class in my MainActivity.class
I'm a begginer android developper, so please i need and easy way to do it.
Thank you all.

@VladimirYugay

This comment has been minimized.

Copy link

@VladimirYugay VladimirYugay commented Dec 16, 2016

Hello guys. In my app this code sometimes doesn't work. However, I need it working even when my activity is dead or a phone is reloaded. What will be the best solution for such a problem? Maybe using a service with the broadcast?
Thanks a lot.

@TeloNguyen

This comment has been minimized.

Copy link

@TeloNguyen TeloNguyen commented Jan 12, 2017

Hello everyone, I meet a difficultly case as I want to detect all detail events for outgoing calling (such as busy call, cannot connect to another phone in a call when they shutdown their device, and not picked up, ...). I researched and tried with many ways, but I failed. In android version < 5.0, I must use hidden and internal android apis, but my issue is I cannot invoke @hide methods, I followed guides for using hidden api on google but I cannot create jar file, so I cannot sure about that way. Also, android 6.0, google public Call class for manage states of call (this link : https://android.googlesource.com/platform/packages/services/Telephony/+/idea133/common/src/com/android/services/telephony/common/Call.java), but I still don't know the way to use this Class. I really need to your support for this. I love any solution from anyone. Please help me.

@kainjinez

This comment has been minimized.

Copy link

@kainjinez kainjinez commented Feb 4, 2017

This may doesnt work with 6.0

2-04 16:16:48.929 560-574/system_process W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to net.truonghieu.whoscall/.receiver.PhoneCallReceiver requires android.permission.READ_PRIVILEGED_PHONE_STATE due to sender android (uid 1000)
0
@VladimirYugay

This comment has been minimized.

Copy link

@VladimirYugay VladimirYugay commented Feb 6, 2017

Hello everybody. The code is great, but I can't register the receiver extended from this one dynamically. It simply doesn't work. Can you help me?

@HoangTV1993

This comment has been minimized.

Copy link

@HoangTV1993 HoangTV1993 commented Mar 23, 2017

Thank you ;)

@hitman9

This comment has been minimized.

Copy link

@hitman9 hitman9 commented Apr 25, 2017

how to use these methods in Mainactivity.java class..to makes it workable..

@hitman9

This comment has been minimized.

Copy link

@hitman9 hitman9 commented Apr 25, 2017

I'm a beginner.. please help..

@manandarajah

This comment has been minimized.

Copy link

@manandarajah manandarajah commented May 7, 2017

Hey, I implemented your class into my project, and nothing seems to be working on my phone. So in my code, I made a toast to test out if it detects incoming calls, and the phone doesn't seem to be doing anything. When I debug it, it calls onIncomingCallStarted method (The toast code is in there) and the debugger debugs through that, but the toast doesn't show up on my actual phone. Is this normal or is there a fix for this?

@Ba6al

This comment has been minimized.

Copy link

@Ba6al Ba6al commented May 15, 2017

I guess for newer Android 6.0 and above you will have to manually give the app permission to run (go to setting then application permission s) this will be needed in addition to the manifest permission statements in the config above.
The problem I am having is that my broadcast receiver is only getting the broadcasts for new outgoing calls but not for the phone status.
Anyone facing the same issue?

@ravivlb

This comment has been minimized.

Copy link

@ravivlb ravivlb commented Jul 12, 2017

Hi,

Code work well. I am looking for to track second call status like Rejected or answered.

Any idea?

@joy2fun

This comment has been minimized.

Copy link

@joy2fun joy2fun commented Jul 30, 2017

@Ba6al THX

@RupeshVM

This comment has been minimized.

Copy link

@RupeshVM RupeshVM commented Sep 28, 2017

Hi,

How i detect waiting call

@Aloyalty

This comment has been minimized.

Copy link

@Aloyalty Aloyalty commented Oct 24, 2017

how to get outgoing call log and receive outgoing call log in my app

@Jalalx

This comment has been minimized.

Copy link

@Jalalx Jalalx commented Nov 12, 2017

Thank you for sharing this. It makes life easier :)

@Paul-weqe

This comment has been minimized.

Copy link

@Paul-weqe Paul-weqe commented Dec 2, 2017

Works but for the calls ending part, not really working there.

In case I get an answer I will update

@alorwu

This comment has been minimized.

Copy link

@alorwu alorwu commented Dec 15, 2017

@Aloyalty a simple approach is to create a separate receiver class (file) for outgoing and register it in the Manifest. That way, you simply get the dialed number. No need for the hard-coded strings.

@alorwu

This comment has been minimized.

Copy link

@alorwu alorwu commented Dec 15, 2017

@hitman9 you don't need a MainActivity for this to work. This is a receiver. It works even without your app running. It listens to system events and if an event matches what you're listening for, it fires the response you've set in your receiver.

@onchukovdenis

This comment has been minimized.

Copy link

@onchukovdenis onchukovdenis commented Jan 15, 2018

Hi, Your code work good. Could you please help me?
How I can end outcoming call?
I try setResultData(null);
but my code work not on all devices

@akomakom

This comment has been minimized.

Copy link

@akomakom akomakom commented Feb 22, 2018

The only part I was missing in the above was manually granting phone permission to the app (despite the manifest entries) in the Android device settings.

@Androidsignal

This comment has been minimized.

Copy link

@Androidsignal Androidsignal commented Apr 5, 2018

please provide full source code ....

@dilshaddkhan

This comment has been minimized.

Copy link

@dilshaddkhan dilshaddkhan commented Apr 26, 2018

thank you for the solution
will you please tell us how could i able to connect the call and get the name of the caller.

@te0tl

This comment has been minimized.

Copy link

@te0tl te0tl commented Apr 27, 2018

thanks, works like a charm

@mtalhashafiq

This comment has been minimized.

Copy link

@mtalhashafiq mtalhashafiq commented May 16, 2018

**I tried this code it is working fine .But problem is that It is receiving calls late sometime after 2 seconds, 5 seconds,15 seconds etc. How to solve this issue? I am developing call blocking application .Plz Help me. **

@cemtufekci

This comment has been minimized.

Copy link

@cemtufekci cemtufekci commented May 17, 2018

it's not working when user kills the app from the recent apps.

@sriramr98

This comment has been minimized.

Copy link

@sriramr98 sriramr98 commented May 23, 2018

This code doesn't work. The incoming call is detected perfectly. When the call is accepted, onOutgoingCallStarted() is called with number as null. The respective callbacks for missed calls, the incoming call ended, the outgoing call ended are never called.
The onOutgoingCallStarted() always gives null as the number.

@pmpavan

This comment has been minimized.

Copy link

@pmpavan pmpavan commented May 25, 2018

Is anyone getting this error in targetSdk 27?

2018-05-25 12:32:36.995 1108-1134/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x1000010 (has extras) } to PACKAGE_NAME.PhoneCallReceiver requires android.permission.READ_PRIVILEGED_PHONE_STATE due to sender android (uid 1000)

@smartraysam

This comment has been minimized.

Copy link

@smartraysam smartraysam commented Jun 4, 2018

hey guy i have issue detecting Incoming calls on sdk 26 and above but work well on sdk below 26.. please any help

@itsmeluige

This comment has been minimized.

Copy link

@itsmeluige itsmeluige commented Jun 27, 2018

Hey man, How to do this in recents APIs, Oreo?

@rakshitsoni02

This comment has been minimized.

@dadajigunjal

This comment has been minimized.

Copy link

@dadajigunjal dadajigunjal commented Aug 12, 2018

Dear Owner,

Can you help me out to detect event (exact time) to someone had received our outgoing call. Not like ..Outgoing Call Started..!
as below
case TelephonyManager.CALL_STATE_OFFHOOK:
//Transition of ringing->offhook are pickups of incoming calls. Nothing done on them
if(lastState != TelephonyManager.CALL_STATE_RINGING){
isIncoming = false;
callStartTime = new Date();
Toast.makeText(context, "Outgoing Call Started" , Toast.LENGTH_SHORT).show();
}case TelephonyManager.CALL_STATE_OFFHOOK:

Expected result : To detect event(trigger) that called user has received your call.
I hope that you will be help me ASAP.

@shaynasharma

This comment has been minimized.

Copy link

@shaynasharma shaynasharma commented Aug 19, 2018

Hey Owner , i want to fetch Call Instance , to find call drop reason and for that I am refering this approach (Using Internal api)(https://stackoverflow.com/questions/34670312/how-to-detect-a-call-drop-in-android.) but for that I want Call Instance which I don't know where I will get please any help.

@msnisha

This comment has been minimized.

Copy link

@msnisha msnisha commented Oct 6, 2018

It worked for me, had to do minor changes to the Gradle build file to align with my current SDK version. Thank you.

@anandgoel1

This comment has been minimized.

Copy link

@anandgoel1 anandgoel1 commented Oct 8, 2018

I used above code. I have asked for Read_Phone_State and Read_Call_Log permission in manifest and Activity Both. I havn't used outgoing permission as I intent to seek incoming number only.

The above code works but only issue is intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER value is null everytime.

I cannot fetch incoming call number? I have registered receiver with android.intent.action.PHONE_STATE intent filter.

CODE:
MANIFEST:

Activity Asking Permissions:
//Code to check Access_Network_State permission to app.
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)== PackageManager.PERMISSION_DENIED) {

            // Log.i("InContactExchange", "asking access_network_state contact permissions...");
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, access_phone_state);
            // Log.i("InContactExchange", String.valueOf(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE)));

        } else {// Log.i("InContactExchange","System already have Access  network state permissions...");
        }

        //Code to check Access_Network_State permission to app.
        if(ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALL_LOG)== PackageManager.PERMISSION_DENIED) {

            // Log.i("InContactExchange", "asking access_network_state contact permissions...");
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CALL_LOG}, read_call_log);
            // Log.i("InContactExchange", String.valueOf(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE)));

        } else {// Log.i("InContactExchange","System already have Access  network state permissions...");
        }

// Relevant set permissions are set

Phone Receiver

public class PhoneCallReceiver extends BroadcastReceiver

{

//interface
private static PhoneListner mListener;


//The receiver will be recreated whenever android feels like it.  We need a static variable to remember data between instantiations

private static int lastState = TelephonyManager.CALL_STATE_IDLE;
private static String savedNumber;  //because the passed incoming is only valid in ringing

@Override
public void onReceive(Context context, Intent intent)
{
    //We listen to two intents.  The new outgoing call only tells us of an outgoing call.  We use it to get the number.
    if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
        savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
    }
    else{
        String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
        String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER); **(//This statement returns null)**
        int state = 0;
        if(stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)){
            state = TelephonyManager.CALL_STATE_IDLE;
        }
        else if(stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
            state = TelephonyManager.CALL_STATE_OFFHOOK;
        }
        else if(stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)){
            state = TelephonyManager.CALL_STATE_RINGING;
        }
        onCallStateChanged(context, state, number);
    }
}
@anandgoel1

This comment has been minimized.

Copy link

@anandgoel1 anandgoel1 commented Oct 8, 2018

This code doesn't work. The incoming call is detected perfectly. When the call is accepted, onOutgoingCallStarted() is called with number as null. The respective callbacks for missed calls, the incoming call ended, the outgoing call ended are never called.
The onOutgoingCallStarted() always gives null as the number.

Did you resolve this issue??

@pmkhue

This comment has been minimized.

Copy link

@pmkhue pmkhue commented Nov 30, 2018

This code doesn't work with target 27 and Android Oreo.

@mablue

This comment has been minimized.

Copy link

@mablue mablue commented Dec 8, 2018

java.lang.RuntimeException: Unable to instantiate receiver com.azharja.takzang.CallListener: java.lang.ClassCastException: com.azharja.takzang.CallListener cannot be cast to android.content.BroadcastReceiver

@AjayLSojitra

This comment has been minimized.

Copy link

@AjayLSojitra AjayLSojitra commented Dec 20, 2018

Such a awesome solution, Thanks buddy :)

@AjayLSojitra

This comment has been minimized.

Copy link

@AjayLSojitra AjayLSojitra commented Dec 20, 2018

@pmkhue there is a permission issue. You have to get READ_PHONE_STATE and PROCESS_OUTGOING_CALLS permission from user for above 6.0 version.

@kdefaoui

This comment has been minimized.

Copy link

@kdefaoui kdefaoui commented Jan 22, 2019

Great Work, thank You

@dev071089

This comment has been minimized.

Copy link

@dev071089 dev071089 commented Feb 18, 2019

FYI..
PROCESS_OUTGOING_CALLS permission is not allowed by Google as per their new policy of permissions.

You can find more detail here

Is there any other way to detect the incoming call?

@ashokstel

This comment has been minimized.

Copy link

@ashokstel ashokstel commented Feb 19, 2019

Works fine but in lenova device dial a call it self going to TelephonyManager.CALL_STATE_OFFHOOK its wrong .Let know any one know.Advance thanks

@napoleondev

This comment has been minimized.

Copy link

@napoleondev napoleondev commented Mar 5, 2019

Great Work, thank You

Hello.
Could you help me? I wanna source code of the main_activity.

@Stevemoretz

This comment has been minimized.

Copy link

@Stevemoretz Stevemoretz commented Mar 10, 2019

Thank you for sharing the code.

@shero333

This comment has been minimized.

Copy link

@shero333 shero333 commented Mar 20, 2019

Hello guys,
It do not picks call in my project. My app is related to speech recognition, where I want my app to pick up the call on asked by speech.... e.g. "Pick the Call!" but it do not pick the call. Kindly, tell me what should I do?

@shero333

This comment has been minimized.

Copy link

@shero333 shero333 commented Mar 20, 2019

Note that I am not the author of the code.

Of course, Please can you help me??? My app is related to speech recognition, where I want my app to pick up the call on asked by speech.... e.g. "Pick the Call!" but it do not pick the call. Kindly, tell me what should I do?

@aymeekouakou

This comment has been minimized.

Copy link

@aymeekouakou aymeekouakou commented Mar 26, 2019

Regarding changes makes on Android Pie, (See https://developer.android.com/about/versions/pie/android-9.0-changes-all#restrict-access-phone-numbers),

You must replace lines 28 - 42 by

TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(new PhoneStateListener() {
     @Override
     public void onCallStateChanged(int state, String phoneNumber) {
          onCustomCallStateChanged(context, state, phoneNumber);
     }
}, PhoneStateListener.LISTEN_CALL_STATE);

And rename onCallStateChanged() method in PhonecallReceiver class by onCustomCallStateChanged()

@harsh023

This comment has been minimized.

Copy link

@harsh023 harsh023 commented Mar 27, 2019

I have problem with getting wrong call type.......like when i'm doing call incoming then it display last call type of call log....what can i do for that?

@rahulmanek

This comment has been minimized.

Copy link

@rahulmanek rahulmanek commented May 23, 2019

Add the following to AndroidManifest.xml

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

<!--This part is inside the application-->
    <receiver android:name=".CallReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
    </receiver>

Usage example:

public class CallReceiver extends PhonecallReceiver {

    @Override
    protected void onIncomingCallStarted(Context ctx, String number, Date start) {
    }

    @Override
    protected void onOutgoingCallStarted(Context ctx, String number, Date start) {
    }

    @Override
    protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end) {
    }

    @Override
    protected void onOutgoingCallEnded(Context ctx, String number, Date start, Date end) {
    }

    @Override
    protected void onMissedCall(Context ctx, String number, Date start) {
    }

}

Do i need to add Activity for this app to run ????

@shahzadafridi

This comment has been minimized.

Copy link

@shahzadafridi shahzadafridi commented Aug 9, 2019

There is no state of answer call. I mean If I call someone and they attend the call then this can be also considered as a state like others (CALL_STATE_OFFHOOK, CALL_STATE_IDLE, CALL_STATE_RINGING ). I don't see such state in all example that exists on the internet. If anyone has info or any reference I would be grateful for that.

@1isten

This comment has been minimized.

Copy link

@1isten 1isten commented Aug 13, 2019

Thank you @ftvs for your nice share! The code works like a charm except for Android 6.0 and above we need to manually popup a dialog to ask the user for the READ_PHONE_STATE permission. For those folks who have trouble implementing this, I've created a repo and the implemented apk: https://github.com/1isten/WhoIsThat/releases, hope that helps.

@catman85

This comment has been minimized.

Copy link

@catman85 catman85 commented Aug 22, 2019

Thank you!

@nikitoSha

This comment has been minimized.

Copy link

@nikitoSha nikitoSha commented Oct 1, 2019

methods from class CallReceiver never calls (onIncoming and so on) if you don't implement in Manifest class CallReceiver.

@Basit-Iqbal

This comment has been minimized.

Copy link

@Basit-Iqbal Basit-Iqbal commented Oct 31, 2019

why u guys need it in MainActivity when u already implement in manifest..

@nikitoSha

This comment has been minimized.

Copy link

@nikitoSha nikitoSha commented Oct 31, 2019

Maybe for callbacks implementation? Don't think so?

@Basit-Iqbal

This comment has been minimized.

Copy link

@Basit-Iqbal Basit-Iqbal commented Oct 31, 2019

yup may be..

@nikitoSha

This comment has been minimized.

Copy link

@nikitoSha nikitoSha commented Oct 31, 2019

This lib and call_log not interested now, because Google removing apps, if they cannot be used as default phone app.

@Basit-Iqbal

This comment has been minimized.

Copy link

@Basit-Iqbal Basit-Iqbal commented Oct 31, 2019

how u sure about that becose presently m working on such kind of project?

@nikitoSha

This comment has been minimized.

Copy link

@nikitoSha nikitoSha commented Oct 31, 2019

Because we can't publish our app without default installing and with call_log permission. Old apps with this permissions will be removed soon. It's an answer from Google play support team via email. So, we already remove permissions and make call detecting another way. Google play team accepts our app

@Basit-Iqbal

This comment has been minimized.

Copy link

@Basit-Iqbal Basit-Iqbal commented Oct 31, 2019

what do you think about this app https://play.google.com/store/apps/details?id=com.personlization.magiccall ? it also uses same permissions.

@nikitoSha

This comment has been minimized.

Copy link

@nikitoSha nikitoSha commented Oct 31, 2019

If user can replace default incoming call application (with photo, number and accept/decline call buttons), this app will be leave and active. Google not remove your app. If your app cannot replace default incoming call app (for answering call), Google will remove this app from store :(
Put changes to your app for default using in operation system and all be okay

@Basit-Iqbal

This comment has been minimized.

Copy link

@Basit-Iqbal Basit-Iqbal commented Oct 31, 2019

thank u so much :)

@nikitoSha

This comment has been minimized.

Copy link

@nikitoSha nikitoSha commented Oct 31, 2019

Okay, good luck!:)

@ri3tykity

This comment has been minimized.

Copy link

@ri3tykity ri3tykity commented Nov 11, 2019

I want to read only incoming call number in marshmallow and above. What should I do? My app got rejected by google so I removed the READ_CALL_LOG and everything is OK. But I want to implement the incoming call read in android. Any idea how to build that? Or any suggestion on how to make default calling app in android.
Thanks in advanced.

@nikitoSha

This comment has been minimized.

Copy link

@nikitoSha nikitoSha commented Nov 12, 2019

I want to read only incoming call number in marshmallow and above. What should I do? My app got rejected by google so I removed the READ_CALL_LOG and everything is OK. But I want to implement the incoming call read in android. Any idea how to build that? Or any suggestion on how to make default calling app in android.
Thanks in advanced.

Handle incoming calls via accessibility

@ehp006

This comment has been minimized.

Copy link

@ehp006 ehp006 commented Feb 27, 2020

Is there a similar method to detect VoIP incoming call start and end in Android programtically ? Thank you

@nikitoSha

This comment has been minimized.

Copy link

@nikitoSha nikitoSha commented Feb 27, 2020

Is there a similar method to detect VoIP incoming call start and end in Android programtically ? Thank you

No. VoIP working over Internet and have private protocol. Look info about SIP.

@amrut192

This comment has been minimized.

Copy link

@amrut192 amrut192 commented Apr 25, 2020

In case of Multi SIM (Dual SIM) devices, is there any way to find out which SIM is receiving the incoming call ?

@nikitoSha

This comment has been minimized.

Copy link

@nikitoSha nikitoSha commented Jul 31, 2020

This sample not working for multiple calls (second incoming, for example)

@arsalankhan994

This comment has been minimized.

Copy link

@arsalankhan994 arsalankhan994 commented Sep 12, 2020

not working on oreo devices

@nikitoSha

This comment has been minimized.

Copy link

@nikitoSha nikitoSha commented Sep 13, 2020

not working on oreo devices

Working

@arsalankhan994

This comment has been minimized.

Copy link

@arsalankhan994 arsalankhan994 commented Sep 13, 2020

not working on oreo devices

Working

have you test this on app kill state?

@Mateeen

This comment has been minimized.

Copy link

@Mateeen Mateeen commented Oct 17, 2020

Regarding changes makes on Android Pie, (See https://developer.android.com/about/versions/pie/android-9.0-changes-all#restrict-access-phone-numbers),

You must replace lines 28 - 42 by

TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(new PhoneStateListener() {
     @Override
     public void onCallStateChanged(int state, String phoneNumber) {
          onCustomCallStateChanged(context, state, phoneNumber);
     }
}, PhoneStateListener.LISTEN_CALL_STATE);

And rename onCallStateChanged() method in PhonecallReceiver class by onCustomCallStateChanged()

That worked for me Thanks

@Mateeen

This comment has been minimized.

Copy link

@Mateeen Mateeen commented Oct 17, 2020

not working on oreo devices

Working

have you test this on app kill state?

it is not working when app removed from recent or its process killed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.