List of usage examples for android.content Intent ACTION_HEADSET_PLUG
String ACTION_HEADSET_PLUG
To view the source code for android.content Intent ACTION_HEADSET_PLUG.
Click Source Link
From source file:org.yammp.MusicPlaybackService.java
@Override public void onCreate() { super.onCreate(); mApplication = (YAMMPApplication) getApplication(); mUtils = mApplication.getMediaUtils(); mPlaybackIntent = new Intent(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mAudioManager.registerMediaButtonEventReceiver( new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName())); mPrefs = new PreferencesEditor(getApplicationContext()); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mShakeDetector = new ShakeListener(this); mCardId = mUtils.getCardId();//from w ww. jav a 2 s. co m registerExternalStorageListener(); registerA2dpServiceListener(); // Needs to be done in this thread, since otherwise // ApplicationContext.getPowerManager() crashes. mPlayer = new MultiPlayer(); mPlayer.setHandler(mMediaplayerHandler); if (mEqualizerSupported) { mEqualizer = new EqualizerWrapper(0, getAudioSessionId()); if (mEqualizer != null) { mEqualizer.setEnabled(true); reloadEqualizer(); } } reloadQueue(); IntentFilter commandFilter = new IntentFilter(); commandFilter.addAction(SERVICECMD); commandFilter.addAction(TOGGLEPAUSE_ACTION); commandFilter.addAction(PAUSE_ACTION); commandFilter.addAction(NEXT_ACTION); commandFilter.addAction(PREVIOUS_ACTION); commandFilter.addAction(CYCLEREPEAT_ACTION); commandFilter.addAction(TOGGLESHUFFLE_ACTION); commandFilter.addAction(BROADCAST_PLAYSTATUS_REQUEST); registerReceiver(mIntentReceiver, commandFilter); registerReceiver(mExternalAudioDeviceStatusReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); mWakeLock.setReferenceCounted(false); // If the service was idle, but got killed before it stopped itself, the // system will relaunch it. Make sure it gets stopped again in that // case. Message msg = mDelayedStopHandler.obtainMessage(); mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY); }
From source file:com.rks.musicx.services.MusicXService.java
@Override public void headsetState() { if (headsetListener != null) { IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); registerReceiver(headsetListener, receiverFilter); }/* www . j av a 2 s. c o m*/ }
From source file:org.sipdroid.sipua.ui.Receiver.java
@Override public void onReceive(Context context, Intent intent) { String intentAction = intent.getAction(); if (!Sipdroid.on(context)) return;/*w ww. j a v a2s.c om*/ if (!Sipdroid.release) Log.i("SipUA:", intentAction); if (mContext == null) mContext = context; if (intentAction.equals(Intent.ACTION_BOOT_COMPLETED)) { on_vpn(false); engine(context).register(); } else if (intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION) || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_AVAILABLE) || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE) || intentAction.equals(Intent.ACTION_PACKAGE_REPLACED)) { engine(context).register(); } else if (intentAction.equals(ACTION_VPN_CONNECTIVITY) && intent.hasExtra("connection_state")) { String state = intent.getSerializableExtra("connection_state").toString(); if (state != null && on_vpn() != state.equals("CONNECTED")) { on_vpn(state.equals("CONNECTED")); for (SipProvider sip_provider : engine(context).sip_providers) if (sip_provider != null) sip_provider.haltConnections(); engine(context).register(); } } else if (intentAction.equals(ACTION_DATA_STATE_CHANGED)) { engine(context).registerMore(); } else if (intentAction.equals(ACTION_PHONE_STATE_CHANGED) && !intent.getBooleanExtra(context.getString(R.string.app_name), false)) { stopRingtone(); pstn_state = intent.getStringExtra("state"); pstn_time = SystemClock.elapsedRealtime(); if (pstn_state.equals("IDLE") && call_state != UserAgent.UA_STATE_IDLE) broadcastCallStateChanged(null, null); if (!pstn_state.equals("IDLE") && call_state == UserAgent.UA_STATE_INCALL) mHandler.sendEmptyMessageDelayed(MSG_HOLD, 5000); else if (!pstn_state.equals("IDLE") && (call_state == UserAgent.UA_STATE_INCOMING_CALL || call_state == UserAgent.UA_STATE_OUTGOING_CALL)) mHandler.sendEmptyMessageDelayed(MSG_HANGUP, 5000); else if (pstn_state.equals("IDLE")) { mHandler.removeMessages(MSG_HOLD); mHandler.removeMessages(MSG_HANGUP); if (call_state == UserAgent.UA_STATE_HOLD) mHandler.sendEmptyMessageDelayed(MSG_HOLD, 1000); } } else if (intentAction.equals(ACTION_DOCK_EVENT)) { docked = intent.getIntExtra(EXTRA_DOCK_STATE, -1) & 7; if (call_state == UserAgent.UA_STATE_INCALL) engine(mContext).speaker(speakermode()); } else if (intentAction.equals(ACTION_SCO_AUDIO_STATE_CHANGED)) { bluetooth = intent.getIntExtra(EXTRA_SCO_AUDIO_STATE, -1); progress(); RtpStreamSender.changed = true; } else if (intentAction.equals(Intent.ACTION_HEADSET_PLUG)) { headset = intent.getIntExtra("state", -1); if (call_state == UserAgent.UA_STATE_INCALL) engine(mContext).speaker(speakermode()); } else if (intentAction.equals(Intent.ACTION_SCREEN_ON)) { if (!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) alarm(0, OwnWifi.class); } else if (intentAction.equals(Intent.ACTION_USER_PRESENT)) { mHandler.sendEmptyMessageDelayed(MSG_ENABLE, 3000); } else if (intentAction.equals(Intent.ACTION_SCREEN_OFF)) { if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); if (wm.getWifiState() != WifiManager.WIFI_STATE_ENABLED || wi == null || wi.getSupplicantState() != SupplicantState.COMPLETED || wi.getIpAddress() == 0) alarm(2 * 60, OwnWifi.class); else alarm(15 * 60, OwnWifi.class); } if (SipdroidEngine.pwl != null) for (PowerManager.WakeLock pwl : SipdroidEngine.pwl) if (pwl != null && pwl.isHeld()) { pwl.release(); pwl.acquire(); } } else if (intentAction.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI)) mHandler.sendEmptyMessageDelayed(MSG_SCAN, 3000); } else if (intentAction.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { if (SystemClock.uptimeMillis() > lastscan + 45000 && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI)) { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); String activeSSID = null; if (wi != null) activeSSID = wi.getSSID(); if (activeSSID != null && (activeSSID.length() == 0 || activeSSID.equals("0x"))) activeSSID = null; List<ScanResult> mScanResults = wm.getScanResults(); List<WifiConfiguration> configurations = wm.getConfiguredNetworks(); if (configurations != null) { WifiConfiguration bestconfig = null, maxconfig = null, activeconfig = null; for (final WifiConfiguration config : configurations) { if (maxconfig == null || config.priority > maxconfig.priority) { maxconfig = config; } if (config.SSID != null && (config.SSID.equals("\"" + activeSSID + "\"") || config.SSID.equals(activeSSID))) activeconfig = config; } ScanResult bestscan = null, activescan = null; if (mScanResults != null) for (final ScanResult scan : mScanResults) { for (final WifiConfiguration config : configurations) { if (config.SSID != null && config.SSID.equals("\"" + scan.SSID + "\"")) { if (bestscan == null || scan.level > bestscan.level) { bestscan = scan; bestconfig = config; } if (config == activeconfig) activescan = scan; } } } if (activescan != null) System.out.println("debug wifi asu(active)" + asu(activescan)); if (bestconfig != null && (activeconfig == null || bestconfig.priority != activeconfig.priority) && asu(bestscan) > asu(activescan) * 1.5 && /* (activeSSID == null || activescan != null) && */ asu(bestscan) > 22) { if (!Sipdroid.release) Log.i("SipUA:", "changing to " + bestconfig.SSID); if (activeSSID == null || !activeSSID.equals(bestscan.SSID)) wm.disconnect(); bestconfig.priority = maxconfig.priority + 1; wm.updateNetwork(bestconfig); wm.enableNetwork(bestconfig.networkId, true); wm.saveConfiguration(); if (activeSSID == null || !activeSSID.equals(bestscan.SSID)) wm.reconnect(); lastscan = SystemClock.uptimeMillis(); } else if (activescan != null && asu(activescan) < 15) { wm.disconnect(); wm.disableNetwork(activeconfig.networkId); wm.saveConfiguration(); } } } } }
From source file:org.restcomm.app.qoslib.Services.Intents.IntentHandler.java
public IntentFilter declareIntentFilters() { IntentFilter intentFilter = new IntentFilter(IntentHandler.UPDATE_ACTION); intentFilter.addAction(IntentHandler.START_TRACKING_ACTION); intentFilter.addAction(IntentHandler.TRACK_REMOTE); intentFilter.addAction(IntentHandler.STOP_TRACKING_ACTION); intentFilter.addAction(IntentHandler.SPEED_TEST); intentFilter.addAction(IntentHandler.RUN_WEBSOCKET); intentFilter.addAction(CommonIntentActionsOld.ACTION_START_UI); intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_UPDATE); intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_LOCATION_UPDATE); intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_CELL_UPDATE); intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_GPS_STATUS_UPDATE); intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_SIGNAL_STRENGTH_UPDATE); intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_EVENT_UPDATE); intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_NEIGHBOR_UPDATE); intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_NETWORK_UPDATE); //intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_RX_TX); intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_RESULT); intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_ERROR); intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_COMPLETE); intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_CANCELLED); intentFilter.addAction(IntentHandler.ACTION_WEBTEST_RESULT); intentFilter.addAction(IntentHandler.ACTION_WEBTEST_ERROR); intentFilter.addAction(IntentHandler.ACTION_WEBTEST_COMPLETE); intentFilter.addAction(IntentHandler.ACTION_WEBTEST_CANCELLED); //do not add filter if sms test permissions aren't all allowed if (PreferenceKeys.getSMSPermissionsAllowed(owner, true)) intentFilter.addAction(IntentHandler.SMS_TEST); intentFilter.addAction(IntentHandler.SMS_DELIVERED); intentFilter.addAction(IntentHandler.LATENCY_TEST); intentFilter.addAction(IntentHandler.ACTION_STOP_SPEEDTEST); intentFilter.addAction(IntentHandler.RESTART_MMC_SERVICE); intentFilter.addAction(IntentHandler.COLDRESET_ACTION); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); intentFilter.addAction(Intent.ACTION_POWER_CONNECTED); intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); intentFilter.addAction(Intent.ACTION_SCREEN_OFF); intentFilter.addAction(Intent.ACTION_SCREEN_ON); intentFilter.addAction(IntentHandler.COMMAND); intentFilter.addAction(IntentHandler.SURVEY); //intentFilter.addAction(Intent.ACTION_VIEW); //intentFilter.addAction("android.intent.PHONE_STATE"); intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); intentFilter.addAction(IntentHandler.ACTION_ALARM_MINUTE); intentFilter.addAction(IntentHandler.ACTION_TRACKING_5MINUTE); intentFilter.addAction(IntentHandler.ACTION_TRACKING_1MINUTE); intentFilter.addAction(IntentHandler.ACTION_ALARM_3HOUR); intentFilter.addAction(IntentHandler.ACTION_ALARM_15MINUTE); intentFilter.addAction(IntentHandler.ACTION_ALARM_SCANAPPS); intentFilter.addAction(IntentHandler.EMAIL_CSV); intentFilter.addAction(IntentHandler.GPS_STATE_OFF); intentFilter.addAction(IntentHandler.GPS_STATE_ON); intentFilter.addAction(IntentHandler.PHONE_CALL_CONNECT); intentFilter.addAction(IntentHandler.PHONE_CALL_DISCONNECT); intentFilter.addAction(IntentHandler.HANDOFF); //intentFilter.addAction(IntentHandler.SMS_SENT); intentFilter.addAction(IntentHandler.SMS_RECEIVED); intentFilter.addAction(Intent.ACTION_SEND); intentFilter.addAction(IntentHandler.MANUAL_PLOTTING_START); intentFilter.addAction(IntentHandler.MANUAL_PLOTTING_END); intentFilter.addAction(IntentHandler.MANUAL_PLOTTING_CANCEL); intentFilter.addAction(IntentHandler.MANUAL_TRANSIT_START); intentFilter.addAction(IntentHandler.MANUAL_TRANSIT_END); intentFilter.addAction(IntentHandler.MANUAL_TRANSIT_CANCEL); intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED); intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); intentFilter.addAction(Intent.ACTION_HEADSET_PLUG); intentFilter.addAction(IntentHandler.ROAMING_ON); intentFilter.addAction(IntentHandler.ROAMING_OFF); intentFilter.addAction(IntentHandler.VIEWING_SIGNAL); intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); intentFilter.addAction("android.intent.action.PRECISE_CALL_STATE"); intentFilter.addAction("android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED"); intentFilter.addAction("android.intent.action.PHONE_STATE"); intentFilter.addAction("android.intent.action.NEW_OUTGOING_CALL"); intentFilter.addAction("android.intent.action.DATA_CONNECTION_CONNECTED_TO_PROVISIONING_APN"); intentFilter.addAction("android.intent.action.ANY_DATA_STATE"); intentFilter.addAction("android.intent.action.ACTION_DATA_CONNECTION_FAILED"); intentFilter.addAction(CommonIntentActionsOld.ACTION_BLUETOOTH_ENDDOWNLOAD); intentFilter.addAction(CommonIntentActionsOld.ACTION_START_VOICETEST); intentFilter.addAction(CommonIntentActionsOld.ACTION_STOP_VOICETEST); intentFilter.addAction(CommonIntentActionsOld.ACTION_TEST_VQ_DEVICE); intentFilter.addAction(IntentHandler.ACTIVE_TEST); intentFilter.addAction(IntentHandler.ACTION_STOP_VIDEOTEST); intentFilter.addAction(IntentHandler.GCM_MESSAGE); intentFilter.addAction("org.restcomm.android.CONNECT_FAILED"); intentFilter.addAction("org.restcomm.android.CALL_STATE"); intentFilter.addAction("org.restcomm.android.DISCONNECT_ERROR"); intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_DISCONNECT); intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_CONNECT); intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_NEIGHBORS); intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_SERVICEMODE); intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_SERVICEMENU); intentFilter.addAction(IntentHandler.ACTION_MMCSYS_VERSION); //intentFilter.addAction(Intent.ACTION_APP_ERROR); int raisePriority = owner.getPackageManager().checkPermission("android.permission.RAISED_THREAD_PRIORITY", owner.getPackageName());/*www. j a va 2 s.c o m*/ // With permission to raise priority for SMS messages if (raisePriority == 0) intentFilter.setPriority(9999999); return intentFilter; }
From source file:com.adityarathi.muo.services.AudioPlaybackService.java
/** * Registers the headset plug receiver./*from w w w . j a v a 2 s.co m*/ */ public void registerHeadsetPlugReceiver() { //Register the headset plug receiver. if (mApp.getSharedPreferences().getString("UNPLUG_ACTION", "PAUSE_MUSIC_PLAYBACK") .equals("PAUSE_MUSIC_PLAYBACK")) { IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); mHeadsetPlugReceiver = new HeadsetPlugBroadcastReceiver(); mService.registerReceiver(mHeadsetPlugReceiver, filter); } }
From source file:com.Duo.music.player.Services.AudioPlaybackService.java
/** * Registers the headset plug receiver.//w w w . j ava 2 s . co m */ public void registerHeadsetPlugReceiver() { //Register the headset plug receiver. if (mApp.getSharedPreferences().getString("UNPLUG_ACTION", "DO_NOTHING").equals("PAUSE_MUSIC_PLAYBACK")) { IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); mHeadsetPlugReceiver = new HeadsetPlugBroadcastReceiver(); mService.registerReceiver(mHeadsetPlugReceiver, filter); } }
From source file:com.rfo.basic.Run.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.v(LOGTAG, "onCreate " + this.toString()); if (Basic.lines == null) { Log.e(LOGTAG, "onCreate: Lost context. Bail out."); finish();/*w w w.ja va 2s.c o m*/ return; } // Log.v(LOGTAG, "isOld " + isOld); if (isOld) { if (theWakeLock != null) { theWakeLock.release(); } if (theWifiLock != null) { theWifiLock.release(); } } theWakeLock = null; theWifiLock = null; isOld = true; ContextManager cm = Basic.getContextManager(); cm.registerContext(ContextManager.ACTIVITY_RUN, this); cm.setCurrent(ContextManager.ACTIVITY_RUN); mConsoleIntent = getIntent(); // keep a reference to the Intent that started Run InitRunVars(); // Establish the output screen setContentView(R.layout.console); TextStyle style = new TextStyle(Basic.defaultTextStyle, Settings.getConsoleTypeface(this)); mConsole = new Basic.ColoredTextAdapter(this, mOutput, style); clearConsole(); lv = (ConsoleListView) findViewById(R.id.console); lv.setAdapter(mConsole); lv.setKeyboardManager(mKeyboardChangeListener); lv.setTextFilterEnabled(false); lv.setBackgroundColor(Settings.getEmptyConsoleColor(this).equals("line") ? mConsole.getLineColor() : mConsole.getBackgroundColor()); // default is "background" if (Settings.getLinedConsole(this)) { lv.setDivider(new ColorDrawable(mConsole.getLineColor())); // override default from theme, sometimes it's invisible if (lv.getDividerHeight() < 1) { lv.setDividerHeight(1); } // make sure the divider shows } else { lv.setDividerHeight(0); // don't show the divider } setVolumeControlStream(AudioManager.STREAM_MUSIC); setRequestedOrientation(Settings.getSreenOrientation(this)); headsetBroadcastReceiver = new BroadcastsHandler(); this.registerReceiver(headsetBroadcastReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); // Listeners for Console Touch lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { triggerInterrupt(Interrupt.CONS_TOUCH_BIT); TouchedConsoleLine = position + 1; ConsoleLongTouch = false; } }); lv.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { triggerInterrupt(Interrupt.CONS_TOUCH_BIT); TouchedConsoleLine = position + 1; ConsoleLongTouch = true; return true; } }); mInterpreter = new Interpreter(); // start the interpreter in a background Thread mInterpreter.start(); }