Example usage for android.telephony TelephonyManager EXTRA_STATE_IDLE

List of usage examples for android.telephony TelephonyManager EXTRA_STATE_IDLE

Introduction

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

Prototype

String EXTRA_STATE_IDLE

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

Click Source Link

Document

Value used with #EXTRA_STATE corresponding to #CALL_STATE_IDLE .

Usage

From source file:com.yangtsaosoftware.pebblemessenger.receivers.CallStateHandler.java

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

    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
    if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
        String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
        Constants.log(LOG_TAG, "A new call is coming:" + incomingNumber);
        Intent inner_intent = new Intent(MessageProcessingService.class.getName());
        inner_intent.putExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_CALL_INCOMING);
        if (incomingNumber != null && !incomingNumber.isEmpty()) {
            inner_intent.putExtra(Constants.BROADCAST_PHONE_NUM, incomingNumber);
            inner_intent.putExtra(Constants.BROADCAST_NAME, Constants.queryNameByNum(context, incomingNumber));
        } else {/*from w  w w . ja v a 2s .c o  m*/
            inner_intent.putExtra(Constants.BROADCAST_PHONE_NUM, "0");
            inner_intent.putExtra(Constants.BROADCAST_NAME,
                    context.getString(R.string.notificationservice_privateNumber));
        }
        LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent);
    } else if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) {
        Constants.log(LOG_TAG, "Call is idle");
        Intent inner_intent = new Intent(MessageProcessingService.class.getName());
        inner_intent.putExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_CALL_IDLE);
        LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent);
        inner_intent = new Intent(PebbleCenter.class.getName());
        inner_intent.putExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_CALL_IDLE);
        LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent);
    } else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) {
        Constants.log(LOG_TAG, "Call is off hook");
        Intent inner_intent = new Intent(PebbleCenter.class.getName());
        inner_intent.putExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_CALL_HOOK);
        LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent);
        inner_intent = new Intent(MessageProcessingService.class.getName());
        inner_intent.putExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_CALL_HOOK);
        LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent);
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.PhoneStateObj.java

private String asText(JSONObject obj) {
    StringBuilder status = new StringBuilder();
    String a = obj.optString(ACTION);
    String b = obj.optString(NUMBER);
    if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(a)) {
        status.append("Calling ");
    } else if (TelephonyManager.EXTRA_STATE_IDLE.equals(a)) {
        status.append("Ending phone call with ");
    } else if (TelephonyManager.EXTRA_STATE_RINGING.equals(a)) {
        status.append("Inbound call from ");
    }//from   www  . jav  a  2s.  c o m
    status.append(b).append(".");
    return status.toString();
}

From source file:com.example.plugin.PhoneListener.java

public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    this.phoneListenerCallbackId = null;
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override//from  w w  w. ja  v a 2 s  .  co m
            public void onReceive(Context context, Intent intent) {
                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;
                    String state;
                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                    updatePhoneState(state, true);
                }
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        cordova.getActivity().registerReceiver(this.receiver, intentFilter);
        this.registered = true;
    }

}

From source file:org.devgeeks.PhoneListener.java

/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 * //from www.j av  a 2s  .c  o  m
 * @param ctx The context of the main Activity.
 */
public void setContext(CordovaInterface ctx) {
    super.setContext(ctx);
    this.phoneListenerCallbackId = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;
                    String state;
                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                    updatePhoneState(state, true);
                }
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        cordova.getActivity().registerReceiver(this.receiver, intentFilter);
    }
}

From source file:com.ripperdesignandmultimedia.phoneblockplugin.PhoneBlockerPlugin.java

/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 * // w ww  . ja v  a2 s  .  c o m
 * @param ctx The context of the main Activity.
 */
public void setContext(CordovaInterface ctx) {
    super.setContext(ctx);
    this.phoneBlockerCallbackId = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;
                    String state;
                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                    updatePhoneState(state, true);
                }
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        cordova.getActivity().registerReceiver(this.receiver, intentFilter);
    }
}

From source file:edu.cmu.plugins.PhoneListener.java

/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 * /*from  ww w .  j a v  a2s .c  o  m*/
 * @param ctx The context of the main Activity.
 */
public void setContext(PhonegapActivity ctx) {
    super.setContext(ctx);
    this.phoneListenerCallbackId = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");

    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent == null) {
                    return;
                }
                String state = "";
                if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
                    state = "SMS_RECEIVED";
                    Log.i(LOG_TAG, state);
                }
                if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;

                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                }
                updatePhoneState(state, true);
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        ctx.registerReceiver(this.receiver, intentFilter);
    }
}

From source file:de.qspool.clementineremote.backend.receivers.ClementinePhoneStateCheck.java

@Override
public void onReceive(Context context, Intent intent) {
    if (App.getApp() == null || App.ClementineConnection == null || App.Clementine == null
            || !App.ClementineConnection.isConnected()) {
        return;/*from   ww w .ja v a2s .c o m*/
    }

    if (!intent.getAction().equals("android.intent.action.PHONE_STATE")) {
        return;
    }

    if (ContextCompat.checkSelfPermission(context,
            Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        return;
    }

    // Check if we need to change the volume
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getApp());
    String volumeString = prefs.getString(SharedPreferencesKeys.SP_CALL_VOLUME, Clementine.DefaultCallVolume);
    int volume = Integer.parseInt(volumeString);

    // Get the pebble settings
    if (prefs.getBoolean(SharedPreferencesKeys.SP_LOWER_VOLUME, true)) {
        // Get the current state of the telephone
        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

        // On Lollipop, the state is broadcasted twice. Only process new states.
        if (lastPhoneState.equals(state))
            return;

        Message msg = Message.obtain();

        LastClementineState lastClementineState = new LastClementineState();
        lastClementineState.load();

        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)
                || state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {

            // Only lower the volume once. When receiving a call, the state is RINGING. On pickup
            // OFFHOOK is broadcasted. So we only need to take action when we previously had the
            // IDLE state.
            if (lastPhoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                lastClementineState.volume = App.Clementine.getVolume();
                lastClementineState.state = App.Clementine.getState();
                lastClementineState.save();

                if (volume >= 0) {
                    msg.obj = ClementineMessageFactory.buildVolumeMessage(Integer.parseInt(volumeString));
                } else {
                    msg.obj = ClementineMessage.getMessage(ClementineRemoteProtocolBuffer.MsgType.PAUSE);
                }
            }
        } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
            if (volume >= 0) {
                msg.obj = ClementineMessageFactory.buildVolumeMessage(lastClementineState.volume);
            } else {
                if (lastClementineState.state.equals(Clementine.State.PLAY)) {
                    msg.obj = ClementineMessage.getMessage(ClementineRemoteProtocolBuffer.MsgType.PLAY);
                }
            }
        }

        // Now send the message
        if (msg != null && msg.obj != null && App.ClementineConnection != null) {
            App.ClementineConnection.mHandler.sendMessage(msg);
        }

        lastPhoneState = state;
    }
}

From source file:com.android.talkback.eventprocessor.AccessibilityEventProcessorTest.java

/**
 * This is a special case: the screen is off and telephony reports that the phone isn't
 * ringing. However, telephony might be a split-second too late; the dialer might appear and
 * send the accessibility event BEFORE telephony switches to ringing state. In this case,
 * we should still process the event!/*ww w.j a va2 s  .  c  o  m*/
 */
@MediumTest
public void testWindowStateChanged_fromDialer_screenOff_notRinging() {
    mMatchEventType = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
    mMatchNode = null;

    if (!simulateTelephonyState(TelephonyManager.EXTRA_STATE_IDLE)) {
        return;
    }
    simulateScreenState(false);
    sendEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, getDialerClassName());

    assertTrue(mMatched);
}

From source file:org.skt.runtime.original.Device.java

/**
 * Listen for telephony events: RINGING, OFFHOOK and IDLE
 * Send these events to all plugins using
 *      DroidGap.onMessage("telephone", "ringing" | "offhook" | "idle")
 *///from w  ww  .  ja v  a2s.c o m
private void initTelephonyReceiver() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    final RuntimeInterface myctx = this.ctx;
    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");
                        myctx.postMessage("telephone", "ringing");
                    } else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        LOG.i(TAG, "Telephone OFFHOOK");
                        myctx.postMessage("telephone", "offhook");
                    } else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        LOG.i(TAG, "Telephone IDLE");
                        myctx.postMessage("telephone", "idle");
                    }
                }
            }
        }
    };

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

From source file:com.android.talkback.eventprocessor.AccessibilityEventProcessorTest.java

@MediumTest
public void testWindowStateChanged_fromDialer_screenOn_notRinging() {
    mMatchEventType = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
    mMatchNode = null;/*from   w  w  w  . ja  v  a 2s  .  c o m*/

    if (!simulateTelephonyState(TelephonyManager.EXTRA_STATE_IDLE)) {
        return;
    }
    simulateScreenState(true);
    sendEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, getDialerClassName());

    assertTrue(mMatched);
}