I am making an App that should be able to detect call state, earlier I was advised to use PreciseCallState
since by default android cannot detect exactly what s
try this,
first of all you take permission like
<uses-permission android:name="android.permission.READ_PRECISE_PHONE_STATE" />
and then create receiver in manifest.xml file like,
<receiver android:name=".OutCallLogger">
<intent-filter>
<action android:name="android.intent.action.PRECISE_CALL_STATE" />
</intent-filter>
</receiver>
and implement onReceive() like this,
public class OutCallLogger extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getIntExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, -2) {
case PreciseCallState.PRECISE_CALL_STATE_IDLE:
Log.d(This.LOG_TAG, "IDLE");
break;
case PreciseCallState.PRECISE_CALL_STATE_DIALING:
Log.d(This.LOG_TAG, "DIALING");
break;
case PreciseCallState.PRECISE_CALL_STATE_ALERTING:
Log.d(This.LOG_TAG, "ALERTING");
break;
case PreciseCallState.PRECISE_CALL_STATE_ACTIVE:
Log.d(This.LOG_TAG, "ACTIVE");
break;
}
}
}
But the permission is defined for special-use applications such as dialers, carrier applications, or ims applications. So how should ordinary applications handle it.
READ_PRECISE_PHONE_STATE public static final String READ_PRECISE_PHONE_STATE Allows read only access to precise phone state. Allows reading of detailed information about phone state for special-use applications such as dialers, carrier applications, or ims applications.
Constant Value: "android.permission.READ_PRECISE_PHONE_STATE"