Example usage for android.telephony TelephonyManager EXTRA_STATE_OFFHOOK

List of usage examples for android.telephony TelephonyManager EXTRA_STATE_OFFHOOK

Introduction

In this page you can find the example usage for android.telephony TelephonyManager EXTRA_STATE_OFFHOOK.

Prototype

String EXTRA_STATE_OFFHOOK

To view the source code for android.telephony TelephonyManager EXTRA_STATE_OFFHOOK.

Click Source Link

Document

Value used with #EXTRA_STATE corresponding to #CALL_STATE_OFFHOOK .

Usage

From source file:org.apache.cordova.CoreAndroid.java

/**
 * Listen for telephony events: RINGING, OFFHOOK and IDLE
 * Send these events to all plugins using
 *      CordovaActivity.onMessage("telephone", "ringing" | "offhook" | "idle")
 *///  w ww . ja  v  a  2  s  .c o m
private void initTelephonyReceiver() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    //final CordovaInterface mycordova = this.cordova;
    this.telephonyReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {

            // If state has changed
            if ((intent != null) && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                if (intent.hasExtra(TelephonyManager.EXTRA_STATE)) {
                    String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
                    if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        LOG.i(TAG, "Telephone RINGING");
                        webView.getPluginManager().postMessage("telephone", "ringing");
                    } else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        LOG.i(TAG, "Telephone OFFHOOK");
                        webView.getPluginManager().postMessage("telephone", "offhook");
                    } else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        LOG.i(TAG, "Telephone IDLE");
                        webView.getPluginManager().postMessage("telephone", "idle");
                    }
                }
            }
        }
    };

    // Register the receiver
    webView.getContext().registerReceiver(this.telephonyReceiver, intentFilter);
}