Example usage for android.telephony TelephonyManager EXTRA_STATE_RINGING

List of usage examples for android.telephony TelephonyManager EXTRA_STATE_RINGING

Introduction

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

Prototype

String EXTRA_STATE_RINGING

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

Click Source Link

Document

Value used with #EXTRA_STATE corresponding to #CALL_STATE_RINGING .

Usage

From source file:com.jsw.callcastreceiver.Call_BroadCastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();//from   w w  w  .j a  v  a2 s  . c  om
    if (bundle != null) {
        String state = bundle.getString(TelephonyManager.EXTRA_STATE);
        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
            String number = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

            Intent newIntent = new Intent(context, Telefon_Activity.class);
            newIntent.putExtra("number", number);
            PendingIntent pending = PendingIntent.getActivity(context, CALLNOTIFICATION, newIntent,
                    PendingIntent.FLAG_ONE_SHOT);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
            builder.setContentTitle("Telefon Activity");
            builder.setSmallIcon(R.mipmap.ic_launcher);
            builder.setContentText("Incoming call from: " + number);
            builder.setDefaults(Notification.DEFAULT_VIBRATE);
            builder.setDefaults(Notification.DEFAULT_LIGHTS);
            //Aadir el objeto PendingItem a la notificicacion
            builder.setContentIntent(pending);
            //Aadir la notificacion al Manager
            NotificationManager notify = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notify.notify(CALLNOTIFICATION, builder.build());
        }
    }
}

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  ww  w. j ava 2  s.co 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:at.bitfire.nophonespam.CallReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(intent.getAction()) && intent
            .getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
        String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
        Log.i(TAG, "Received call: " + incomingNumber);

        Settings settings = new Settings(context);
        if (TextUtils.isEmpty(incomingNumber)) {
            // private number (no caller ID)
            if (settings.blockHiddenNumbers())
                rejectCall(context, null);

        } else {//from   w w w . j a v  a  2s . c o m
            DbHelper dbHelper = new DbHelper(context);
            try {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                Cursor c = db.query(Number._TABLE, null, "? LIKE " + Number.NUMBER,
                        new String[] { incomingNumber }, null, null, null);
                if (c.moveToNext()) {
                    ContentValues values = new ContentValues();
                    DatabaseUtils.cursorRowToContentValues(c, values);
                    Number number = Number.fromValues(values);

                    rejectCall(context, number);

                    values.clear();
                    values.put(Number.LAST_CALL, System.currentTimeMillis());
                    values.put(Number.TIMES_CALLED, number.timesCalled + 1);
                    db.update(Number._TABLE, values, Number.NUMBER + "=?", new String[] { number.number });

                    BlacklistObserver.notifyUpdated();
                }
                c.close();
            } finally {
                dbHelper.close();
            }
        }
    }
}

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 .jav 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  w  w  w.j  ava 2 s  .  co 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.szanata.cordova.phonestatechangelistener.PhoneStateChangeListener.java

/**
 * creates a new BroadcastReceiver to listen whether the Telephony State changes
 *//*w w  w  .  jav  a  2  s .com*/
public void startPhoneListener(final CallbackContext callbackContext) {

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

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

                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    String state = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : NONE;
                    String number = "";

                    if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
                    }

                    final JSONObject data = new JSONObject();
                    try {
                        data.put("state", state);
                        data.put("number", number);
                        callbackContext.success(data);
                    } catch (final JSONException e) {
                        callbackContext.error(e.getMessage());
                    }

                }
            }
        };

        this.context.registerReceiver(this.receiver,
                new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED));
    }
}

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.
 * /*from w  w  w .  j a v  a  2  s.  co 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:com.szanata.cordova.plugins.PhoneStateChangeListener.java

/**
 * creates a new BroadcastReceiver to listen whether the Telephony State changes
 *//* ww  w  .  jav  a2 s  .c o m*/
public void startPhoneListener() {

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

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

                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    String state = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : NONE;
                    String number = "";

                    if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
                    }
                    if (callbackContext != null) {
                        final JSONObject data = new JSONObject();
                        try {
                            data.put("state", state);
                            data.put("number", number);
                        } catch (final JSONException e) {
                        }
                        ;
                        callbackContext.success(data);
                    }
                }
            }
        };

        this.context.registerReceiver(this.receiver,
                new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED));
    }
}

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   w  ww. j a va2  s.com*/
 * @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: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 ");
    }//www .  j ava2 s . com
    status.append(b).append(".");
    return status.toString();
}