How to Use PreciseCallState

后端 未结 2 811

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

相关标签:
2条回答
  • 2021-01-06 17:02

    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;
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-06 17:20

    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"

    0 讨论(0)
提交回复
热议问题