Skip to content Skip to sidebar Skip to footer

How To Use Precisecallstate

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 state the call is in,

Solution 1:

try this,

first of all you take permission like

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

and then create receiver in manifest.xml file like,

<receiverandroid:name=".OutCallLogger"><intent-filter><actionandroid:name="android.intent.action.PRECISE_CALL_STATE" /></intent-filter></receiver>

and implement onReceive() like this,

publicclassOutCallLoggerextendsBroadcastReceiver {

    @OverridepublicvoidonReceive(Context context, Intent intent) {
        switch (intent.getIntExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, -2) {
            casePreciseCallState.PRECISE_CALL_STATE_IDLE:
                Log.d(This.LOG_TAG, "IDLE");
                break;
            casePreciseCallState.PRECISE_CALL_STATE_DIALING:
                Log.d(This.LOG_TAG, "DIALING");
                break;
            casePreciseCallState.PRECISE_CALL_STATE_ALERTING:
                Log.d(This.LOG_TAG, "ALERTING");
                break;
            casePreciseCallState.PRECISE_CALL_STATE_ACTIVE:
                Log.d(This.LOG_TAG, "ACTIVE");
                break;
        }
    }
}

Solution 2:

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"

Post a Comment for "How To Use Precisecallstate"