List of usage examples for android.telephony TelephonyManager EXTRA_STATE_RINGING
String EXTRA_STATE_RINGING
To view the source code for android.telephony TelephonyManager EXTRA_STATE_RINGING.
Click Source Link
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 w ww.ja v a2 s . 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: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 ww w . ja va2s .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:com.android.talkback.eventprocessor.AccessibilityEventProcessorTest.java
@MediumTest public void testWindowStateChanged_fromDialer_screenOff_ringing() { mMatchEventType = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED; mMatchNode = null;/*ww w . j av a2 s .c o m*/ if (!simulateTelephonyState(TelephonyManager.EXTRA_STATE_RINGING)) { return; } simulateScreenState(false); sendEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, getDialerClassName()); assertTrue(mMatched); }
From source file:org.durka.hallmonitor.CoreReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) || intent.getAction().equals(QUICKBOOT_POWERON) || intent.getAction().equals(HTC_QUICKBOOT_POWERON)) { Log.d(LOG_TAG + ".boot", "Boot called."); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean("pref_enabled", false)) { Intent mIntent = new Intent(context, CoreService.class); context.startService(mIntent); }/*from ww w . ja v a 2 s. c om*/ } if (CoreStateManager.getInitialized()) { localContext = CoreStateManager.getContext(); mStateManager = ((CoreApp) localContext).getStateManager(); } else { return; } if (!mStateManager.getPreference().getBoolean("pref_enabled", false)) { return; } mStateManager.acquireCPUGlobal(); if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { Log.d(LOG_TAG + ".screen", "Screen on event received."); if (mStateManager.getCoverClosed()) { Log.d(LOG_TAG + ".screen", "Cover is closed, display Default Activity."); mStateManager.setBlackScreenTime(0); Intent mIntent = new Intent(localContext, CoreService.class); mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY); mStateManager.sendToCoreService(mIntent); } else { // Log.d(LOG_TAG + ".screen", // "Cover is open, free everything."); // mStateManager.freeDevice(); Log.d(LOG_TAG + ".screen", "Cover is open, send to background."); Intent stbDAIntent = new Intent(CoreApp.DA_ACTION_SEND_TO_BACKGROUND); LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(stbDAIntent); } } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { Log.d(LOG_TAG + ".screen", "Screen off event received."); // mStateManager.freeDevice(); } else if (intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) { Intent batteryDAIntent = new Intent(CoreApp.DA_ACTION_BATTERY_REFRESH); LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(batteryDAIntent); Intent mIntent = new Intent(localContext, CoreService.class); mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE); mStateManager.sendToCoreService(mIntent); } else if (intent.getAction().equals(Intent.ACTION_POWER_DISCONNECTED)) { Intent batteryDAIntent = new Intent(CoreApp.DA_ACTION_BATTERY_REFRESH); LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(batteryDAIntent); Intent mIntent = new Intent(localContext, CoreService.class); mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE); mStateManager.sendToCoreService(mIntent); } else if (intent.getAction().equals(ALARM_ALERT_ACTION)) { Log.d(LOG_TAG + ".alarm", "Alarm on event received."); // only take action if alarm controls are enabled if (mStateManager.getPreference().getBoolean("pref_alarm_controls", false)) { Log.d(LOG_TAG + ".alarm", "Alarm controls are enabled, taking action."); mStateManager.setAlarmFiring(true); Intent mIntent = new Intent(localContext, CoreService.class); mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_INCOMMING_ALARM); mStateManager.sendToCoreService(mIntent); } else { Log.d(LOG_TAG + ".alarm", "Alarm controls are not enabled."); } } else if (intent.getAction().equals(ALARM_DONE_ACTION)) { Log.d(LOG_TAG + ".alarm", "Alarm done event received."); // only take action if alarm controls are enabled if (mStateManager.getPreference().getBoolean("pref_alarm_controls", false)) { Log.d(mStateManager.getPreference() + ".alarm", "alarm is over, cleaning up"); mStateManager.setAlarmFiring(false); if (mStateManager.getCoverClosed()) { Intent mIntent = new Intent(localContext, CoreService.class); mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY); mStateManager.sendToCoreService(mIntent); } } } else if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) { if (mStateManager.getPreference().getBoolean("pref_phone_controls", false)) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); Log.d(LOG_TAG + ".phone", "phone state changed to " + state); if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { Intent mIntent; mStateManager.setPhoneRinging(true); mStateManager.setCallFrom(intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER)); Log.d(LOG_TAG, "call from " + mStateManager.getCallFrom()); mIntent = new Intent(localContext, CoreService.class); mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_INCOMMING_CALL); mStateManager.sendToCoreService(mIntent); } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) { Intent mIntent; mStateManager.setPhoneRinging(false); Log.d(LOG_TAG, "call is over, cleaning up"); if (mStateManager.getCoverClosed()) { mIntent = new Intent(localContext, CoreService.class); mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY); mStateManager.sendToCoreService(mIntent); } } else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { } } else { Log.d(LOG_TAG + ".phone", "phone controls are not enabled"); } } else if (intent.getAction().equals(mStateManager.getActionCover())) { int state = intent.getIntExtra(EXTRA_LID_STATE, LID_ABSENT); Log.d(LOG_TAG + ".cover", "cover state changed to " + state); if (state == LID_CLOSED) { Log.d(LOG_TAG + ".cover", "Cover is close, enable Default Activity."); mStateManager.setCoverClosed(true); Intent mIntent = new Intent(localContext, CoreService.class); mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY); mStateManager.sendToCoreService(mIntent); } else if (state == LID_OPEN) { // Log.d(LOG_TAG + ".cover", // "Cover is open, stopping Default Activity."); mStateManager.setCoverClosed(false); // mStateManager.freeDevice(); Log.d(LOG_TAG + ".screen", "Cover is open, send to background."); Intent stbDAIntent = new Intent(CoreApp.DA_ACTION_SEND_TO_BACKGROUND); LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(stbDAIntent); Intent mIntent = new Intent(localContext, CoreService.class); mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE); mStateManager.sendToCoreService(mIntent); } } else if (intent.getAction().equals(TORCH_STATE_CHANGED)) { if (mStateManager.getPreference().getBoolean("pref_flash_controls", false)) { Log.d(LOG_TAG + ".torch", "torch state changed"); Intent mIntent = new Intent(localContext, CoreService.class); mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_TORCH_STATE); if (intent.getIntExtra("state", 0) != 0) { mIntent.putExtra(CoreApp.CS_EXTRA_STATE, true); } else { mIntent.putExtra(CoreApp.CS_EXTRA_STATE, false); } mStateManager.sendToCoreService(mIntent); } else { Log.d(LOG_TAG + ".torch", "torch controls are not enabled."); } } else if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) { int state = intent.getExtras().getInt("state"); Log.d(LOG_TAG + ".headset", "headset is " + (state == 0 ? "gone" : "here") + "!"); Intent mIntent = new Intent(localContext, CoreService.class); mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_HEADSET_PLUG); mStateManager.sendToCoreService(mIntent); } else if (intent.getAction().equals("org.durka.hallmonitor.debug")) { Log.d(LOG_TAG + "", "received debug intent"); // test intent to show/hide a notification boolean showhide = false; switch (intent.getIntExtra("notif", 0)) { case 1: showhide = true; break; case 2: showhide = false; break; } if (showhide) { Notification.Builder mBuilder = new Notification.Builder(localContext) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Hall Monitor") .setContentText("Debugging is fun!"); NotificationManager mNotificationManager = (NotificationManager) localContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(42, mBuilder.build()); } else { NotificationManager mNotificationManager = (NotificationManager) localContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.cancel(42); } } mStateManager.releaseCPUGlobal(); }
From source file:org.apache.cordova.App.java
/** * Listen for telephony events: RINGING, OFFHOOK and IDLE * Send these events to all plugins using * CordovaActivity.onMessage("telephone", "ringing" | "offhook" | "idle") *///from ww w . java 2 s .co 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.postMessage("telephone", "ringing"); } else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { LOG.i(TAG, "Telephone OFFHOOK"); webView.postMessage("telephone", "offhook"); } else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) { LOG.i(TAG, "Telephone IDLE"); webView.postMessage("telephone", "idle"); } } } } }; // Register the receiver this.cordova.getActivity().registerReceiver(this.telephonyReceiver, intentFilter); }
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 a2 s.com*/ 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); }