List of usage examples for android.telephony TelephonyManager EXTRA_STATE
String EXTRA_STATE
To view the source code for android.telephony TelephonyManager EXTRA_STATE.
Click Source Link
From source file:com.jsw.callcastreceiver.Call_BroadCastReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras();//from ww w . j a v a 2 s . com 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 w w w . j a v a 2 s . com 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 {/* ww w . j ava 2 s . co 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/* w w w . j av a 2 s.c o 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. * /*ww w. j a v 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. * /*from www . 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:com.szanata.cordova.phonestatechangelistener.PhoneStateChangeListener.java
/** * creates a new BroadcastReceiver to listen whether the Telephony State changes *//*from w ww . j ava2 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.szanata.cordova.plugins.PhoneStateChangeListener.java
/** * creates a new BroadcastReceiver to listen whether the Telephony State changes *///from ww w . j a v a2 s. co 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. * // ww w. j av a2 s . co 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 . java 2 s .co 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; } }