List of usage examples for android.telephony TelephonyManager ACTION_PHONE_STATE_CHANGED
String ACTION_PHONE_STATE_CHANGED
To view the source code for android.telephony TelephonyManager ACTION_PHONE_STATE_CHANGED.
Click Source Link
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 ww w . jav a2 s. 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: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 w w . ja va 2 s. 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: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 ww .j a v a 2 s . c om*/ 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 a2s. 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 w w w . ja v a2 s. c om*/ * @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 a va 2 s . c om 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 w w w .j ava2 s . c om 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: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") *//* w w w . ja v a2s . c om*/ 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:it.unicaradio.android.services.StreamingService.java
private void initReceivers() { registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); registerReceiver(telephonyReceiver, new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED)); registerReceiver(noisyAudioStreamReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY)); }
From source file:com.DorsetEggs.waver.communicatorService.java
/** * The IntentService calls this method from the default worker thread with * the intent that started the service. When this method returns, IntentService * stops the service, as appropriate.//from ww w . j a v a 2 s . c o m */ @Override protected void onHandleIntent(Intent intent) { //Using the the flag to decide if this is a singleton sendDebugMessage("Intent handled, active == true"); /*if(!active)*/ { //android.os.Debug.waitForDebugger(); callOngoing = false; sendDebugMessage("Waiting for connection"); instantiateAnimation(); mUsbManager = UsbManager.getInstance(this); mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter usbFilter = new IntentFilter(ACTION_USB_PERMISSION); usbFilter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); registerReceiver(mUsbReceiver, usbFilter); IntentFilter callFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); registerReceiver(mCallReceiver, callFilter); if (mAccessory != null) { setConnectionStatus(true); return; } UsbAccessory[] accessories = mUsbManager.getAccessoryList(); UsbAccessory accessory = (accessories == null ? null : accessories[0]); if (accessory != null) { sendDebugMessage("USB ready"); if (mUsbManager.hasPermission(accessory)) { openAccessory(accessory); active = true; launchNotification(mId, "Indi connected"); resetMotors(); //Initialise the database SQLiteDatabase db = globals.dbHelper.getWritableDatabase(); } else { setConnectionStatus(false); synchronized (mUsbReceiver) { if (!mPermissionRequestPending) { mUsbManager.requestPermission(accessory, mPermissionIntent); mPermissionRequestPending = true; } } } } else { setConnectionStatus(false); if (D) sendDebugMessage("mAccessory is null"); } // Play here until the phone is disconnected while (true) ; } }