Broadcast Receiver for Missed Call in Android

Missed call detection in android

Hi everyone I have got the solution now its working fine with missed call.

Here my Class code MyCallListener extended by BroadcastReciever

private static boolean ring=false;
private static boolean callReceived=false;
private String callerPhoneNumber;
private Context saveContext;

@Override
public void onReceive(Context mContext, Intent intent)
{
saveContext=mContext;
// Get the current Phone State

String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

if(state==null){
return;
}

Bundle bundle = intent.getExtras();
number= bundle.getString("incoming_number");
Calendar calendar=Calendar.getInstance();
currentTimeStamp=calendar.getTimeInMillis();
// If phone state "Rininging"
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
ring =true;
// Get the Caller's Phone Number

}

// If incoming call is received
if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
{
callReceived=true;
}

// If phone is Idle
if (state.equals(TelephonyManager.EXTRA_STATE_IDLE))
{
// If phone was ringing(ring=true) and not received(callReceived=false) , then it is a missed call
if(ring==true&&callReceived==false)
{
Toast.makeText(mContext, "missed call : "+number, Toast.LENGTH_LONG).show();
//workingWithFunctions();
ring=false;
}
callReceived=false;
}}

dont forgot to define receiver in manifest file

 <receiver android:name="com.abc.broadcastrecivers.MyBroadcastReciver" />

in the application tag

broadcast receiver for missed call in android

There is no specific broadcast for a missed call, AFAIK.

You can watch for ACTION_PHONE_STATE_CHANGED broadcasts, wait until the phone shifts from EXTRA_STATE_RINGING to EXTRA_STATE_IDLE, then try checking the CallLog content provider to see if the call was missed. I have not tried this technique, but it may work.

handle a missed call with broadcast receiver in android

I suppose you could use PhoneStateListener to listen for call state change from CALL_STATE_RINGING to CALL_STATE_IDLE which indicates the phone was not picked up.

Android detect missed call

You can not store any "state" information in a broadcast receiver. If you want to do a comparison old state / new state, I think you can use a service.

android oreo get incoming call number in service

From android 9, read call log permission is required. The permissions were missing.

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


Related Topics



Leave a reply



Submit