Java Code Examples for android.content.Intent#ACTION_HEADSET_PLUG
The following examples show how to use
android.content.Intent#ACTION_HEADSET_PLUG .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeadSetReceiver.java From FamilyChat with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); switch (action) { //插入和拔出耳机会触发此广播 case Intent.ACTION_HEADSET_PLUG: int state = intent.getIntExtra("state", 0); if (state == 1) { //耳机插入 if (mListener != null) mListener.onHeadSetStateChanged(true); } else if (state == 0) { //耳机拔出 if (mListener != null) mListener.onHeadSetStateChanged(false); } break; default: break; } }
Example 2
Source File: WebRtcCallService.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private void registerWiredHeadsetStateReceiver() { wiredHeadsetStateReceiver = new WiredHeadsetStateReceiver(); String action; if (Build.VERSION.SDK_INT >= 21) { action = AudioManager.ACTION_HEADSET_PLUG; } else { action = Intent.ACTION_HEADSET_PLUG; } registerReceiver(wiredHeadsetStateReceiver, new IntentFilter(action)); }
Example 3
Source File: PMedia.java From PHONK with GNU General Public License v3.0 | 5 votes |
public void onHeadsetConnection(ReturnInterface callbackfn) { headsetCallbackfn = callbackfn; IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); headsetPluggedReceiver = new HeadSetReceiver(); getContext().registerReceiver(headsetPluggedReceiver, filter); }
Example 4
Source File: ActivityCall.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void onResume() { super.onResume(); if (callTYpe == ProtoSignalingOffer.SignalingOffer.Type.VIDEO_CALLING) { G.onVideoCallFrame = ActivityCall.this; WebRTC.getInstance().startVideoCapture(); } mSensorManager.registerListener(sensorEventListener, mProximity, SensorManager.SENSOR_DELAY_NORMAL); IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); registerReceiver(headsetPluginReciver, filter); }
Example 5
Source File: CustomTwilioVideoView.java From react-native-twilio-video-webrtc with MIT License | 5 votes |
public CustomTwilioVideoView(ThemedReactContext context) { super(context); this.themedReactContext = context; this.eventEmitter = themedReactContext.getJSModule(RCTEventEmitter.class); // add lifecycle for onResume and on onPause themedReactContext.addLifecycleEventListener(this); /* * Enable changing the volume using the up/down keys during a conversation */ if (themedReactContext.getCurrentActivity() != null) { themedReactContext.getCurrentActivity().setVolumeControlStream(AudioManager.STREAM_VOICE_CALL); } /* * Needed for setting/abandoning audio focus during call */ audioManager = (AudioManager) themedReactContext.getSystemService(Context.AUDIO_SERVICE); myNoisyAudioStreamReceiver = new BecomingNoisyReceiver(); intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); // Create the local data track // localDataTrack = LocalDataTrack.create(this); localDataTrack = LocalDataTrack.create(getContext()); // Start the thread where data messages are received dataTrackMessageThread.start(); dataTrackMessageThreadHandler = new Handler(dataTrackMessageThread.getLooper()); }
Example 6
Source File: MainActivity.java From webTube with GNU General Public License v3.0 | 5 votes |
@Override public void onResume() { super.onResume(); backgroundPlayHelper.hideBackgroundPlaybackNotification(); IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); registerReceiver(headSetReceiver, filter); }
Example 7
Source File: MainActivity.java From webTube with GNU General Public License v3.0 | 5 votes |
@Override public void onResume() { super.onResume(); backgroundPlayHelper.hideBackgroundPlaybackNotification(); IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); registerReceiver(headSetReceiver, filter); }
Example 8
Source File: WebRTCDemo.java From webrtc-app-mono with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate"); super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); populateCameraOrientations(); setContentView(R.layout.tabhost); IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().compareTo(Intent.ACTION_HEADSET_PLUG) == 0) { int state = intent.getIntExtra("state", 0); Log.v(TAG, "Intent.ACTION_HEADSET_PLUG state: " + state + " microphone: " + intent.getIntExtra("microphone", 0)); if (voERunning) { routeAudio(state == 0 && cbEnableSpeaker.isChecked()); } } } }; registerReceiver(receiver, receiverFilter); mTabHost = getTabHost(); // Main tab mTabSpecVideo = mTabHost.newTabSpec("tab_video"); mTabSpecVideo.setIndicator("Main"); mTabSpecVideo.setContent(R.id.tab_video); mTabHost.addTab(mTabSpecVideo); // Shared config tab mTabHost = getTabHost(); mTabSpecConfig = mTabHost.newTabSpec("tab_config"); mTabSpecConfig.setIndicator("Settings"); mTabSpecConfig.setContent(R.id.tab_config); mTabHost.addTab(mTabSpecConfig); TabSpec mTabv; mTabv = mTabHost.newTabSpec("tab_vconfig"); mTabv.setIndicator("Video"); mTabv.setContent(R.id.tab_vconfig); mTabHost.addTab(mTabv); TabSpec mTaba; mTaba = mTabHost.newTabSpec("tab_aconfig"); mTaba.setIndicator("Audio"); mTaba.setContent(R.id.tab_aconfig); mTabHost.addTab(mTaba); int childCount = mTabHost.getTabWidget().getChildCount(); for (int i = 0; i < childCount; i++) { mTabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50; } orientationListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_UI) { public void onOrientationChanged (int orientation) { if (orientation != ORIENTATION_UNKNOWN) { currentDeviceOrientation = orientation; compensateCameraRotation(); } } }; orientationListener.enable (); // Create a folder named webrtc in /scard for debugging webrtcDebugDir = Environment.getExternalStorageDirectory().toString() + webrtcName; File webrtcDir = new File(webrtcDebugDir); if (!webrtcDir.exists() && webrtcDir.mkdir() == false) { Log.v(TAG, "Failed to create " + webrtcDebugDir); } else if (!webrtcDir.isDirectory()) { Log.v(TAG, webrtcDebugDir + " exists but not a folder"); webrtcDebugDir = null; } startMain(); if (AUTO_CALL_RESTART_DELAY_MS > 0) startOrStop(); }
Example 9
Source File: ServicePlayer.java From freemp with Apache License 2.0 | 4 votes |
@Override public void onCreate() { super.onCreate(); // initialize default output device if (!BASS.BASS_Init(-1, 44100, 0)) { return; } // look for plugins plugins = ""; String path = getApplicationInfo().nativeLibraryDir; String[] list = new File(path).list(); for (String s : list) { int plug = BASS.BASS_PluginLoad(path + "/" + s, 0); if (plug != 0) { // plugin loaded... plugins += s + "\n"; // add it to the list } } if (plugins.equals("")) plugins = "no plugins - visit the BASS webpage to get some\n"; if (activity != null) { activity.onPluginsLoaded(plugins); } BASS.BASS_SetConfig(BASS.BASS_CONFIG_BUFFER, 1000); Log.w("BASS.BASS_CONFIG_BUFFER", "" + BASS.BASS_GetConfig(BASS.BASS_CONFIG_BUFFER)); //screen screenHeight = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt("screenHeight", 1000); screenWidth = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt("screenWidth", 800); // Pending Intend Intent intent = new Intent(this, ActPlayer.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); pendIntent = PendingIntent.getActivity(this, 0, intent, 0); //tracklist updateTrackList(); tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm.listen(telephone, PhoneStateListener.LISTEN_CALL_STATE); myBroadcastReceiver = new MyBroadcastReceiver(); IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); intentFilter.addAction("android.media.VOLUME_CHANGED_ACTION"); intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); registerReceiver(myBroadcastReceiver, intentFilter); mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); ComponentName rcvMedia = new ComponentName(getPackageName(), RcvMediaControl.class.getName()); mAudioManager.registerMediaButtonEventReceiver(rcvMedia); // Use the remote control APIs (if available) to set the playback state if (android.os.Build.VERSION.SDK_INT >= 14 && remoteControlClient == null) { registerRemoteControl(rcvMedia); } }
Example 10
Source File: AppRTCAudioManager.java From restcomm-android-sdk with GNU Affero General Public License v3.0 | 4 votes |
/** * Registers receiver for the broadcasted intent when a wired headset is * plugged in or unplugged. The received intent will have an extra * 'state' value where 0 means unplugged, and 1 means plugged. */ private void registerForWiredHeadsetIntentBroadcast() { IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); /** Receiver which handles changes in wired headset availability. */ wiredHeadsetReceiver = new BroadcastReceiver() { private static final int STATE_UNPLUGGED = 0; private static final int STATE_PLUGGED = 1; private static final int HAS_NO_MIC = 0; private static final int HAS_MIC = 1; @Override public void onReceive(Context context, Intent intent) { int state = intent.getIntExtra("state", STATE_UNPLUGGED); int microphone = intent.getIntExtra("microphone", HAS_NO_MIC); String name = intent.getStringExtra("name"); RCLogger.d(TAG, "BroadcastReceiver.onReceive" + AppRTCUtils.getThreadInfo() + ": " + "a=" + intent.getAction() + ", s=" + (state == STATE_UNPLUGGED ? "unplugged" : "plugged") + ", m=" + (microphone == HAS_MIC ? "mic" : "no mic") + ", n=" + name + ", sb=" + isInitialStickyBroadcast()); switch (state) { case STATE_UNPLUGGED: updateAudioDeviceState(false); break; case STATE_PLUGGED: updateAudioDeviceState(true); break; default: RCLogger.e(TAG, "Invalid state"); break; } } }; apprtcContext.registerReceiver(wiredHeadsetReceiver, filter); }
Example 11
Source File: VOIPVideoActivity.java From voip_android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onResume() { IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); registerReceiver(headsetReceiver, filter); super.onResume(); }
Example 12
Source File: AudioManagerAndroid.java From 365browser with Apache License 2.0 | 4 votes |
/** * Registers receiver for the broadcasted intent when a wired headset is * plugged in or unplugged. The received intent will have an extra * 'state' value where 0 means unplugged, and 1 means plugged. */ private void registerForWiredHeadsetIntentBroadcast() { IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); /** Receiver which handles changes in wired headset availability. */ mWiredHeadsetReceiver = new BroadcastReceiver() { private static final int STATE_UNPLUGGED = 0; private static final int STATE_PLUGGED = 1; private static final int HAS_NO_MIC = 0; private static final int HAS_MIC = 1; @Override public void onReceive(Context context, Intent intent) { int state = intent.getIntExtra("state", STATE_UNPLUGGED); if (DEBUG) { int microphone = intent.getIntExtra("microphone", HAS_NO_MIC); String name = intent.getStringExtra("name"); logd("BroadcastReceiver.onReceive: a=" + intent.getAction() + ", s=" + state + ", m=" + microphone + ", n=" + name + ", sb=" + isInitialStickyBroadcast()); } switch (state) { case STATE_UNPLUGGED: synchronized (mLock) { // Wired headset and earpiece and USB audio are mutually exclusive. mAudioDevices[DEVICE_WIRED_HEADSET] = false; if (hasUsbAudio()) { mAudioDevices[DEVICE_USB_AUDIO] = true; mAudioDevices[DEVICE_EARPIECE] = false; } else if (hasEarpiece()) { mAudioDevices[DEVICE_EARPIECE] = true; mAudioDevices[DEVICE_USB_AUDIO] = false; } } break; case STATE_PLUGGED: synchronized (mLock) { // Wired headset and earpiece and USB audio are mutually exclusive. mAudioDevices[DEVICE_WIRED_HEADSET] = true; mAudioDevices[DEVICE_EARPIECE] = false; mAudioDevices[DEVICE_USB_AUDIO] = false; } break; default: loge("Invalid state"); break; } // Update the existing device selection, but only if a specific // device has already been selected explicitly. if (deviceHasBeenRequested()) { updateDeviceActivation(); } else if (DEBUG) { reportUpdate(); } } }; // Note: the intent we register for here is sticky, so it'll tell us // immediately what the last action was (plugged or unplugged). // It will enable us to set the speakerphone correctly. ContextUtils.getApplicationContext().registerReceiver(mWiredHeadsetReceiver, filter); }
Example 13
Source File: AppRTCAudioManager.java From Yahala-Messenger with MIT License | 4 votes |
/** * Registers receiver for the broadcasted intent when a wired headset is * plugged in or unplugged. The received intent will have an extra * 'state' value where 0 means unplugged, and 1 means plugged. */ private void registerForWiredHeadsetIntentBroadcast() { IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); /** Receiver which handles changes in wired headset availability. */ wiredHeadsetReceiver = new BroadcastReceiver() { private static final int STATE_UNPLUGGED = 0; private static final int STATE_PLUGGED = 1; private static final int HAS_NO_MIC = 0; private static final int HAS_MIC = 1; @Override public void onReceive(Context context, Intent intent) { int state = intent.getIntExtra("state", STATE_UNPLUGGED); int microphone = intent.getIntExtra("microphone", HAS_NO_MIC); String name = intent.getStringExtra("name"); Log.d(TAG, "BroadcastReceiver.onReceive" + AppRTCUtils.getThreadInfo() + ": " + "a=" + intent.getAction() + ", s=" + (state == STATE_UNPLUGGED ? "unplugged" : "plugged") + ", m=" + (microphone == HAS_MIC ? "mic" : "no mic") + ", n=" + name + ", sb=" + isInitialStickyBroadcast()); boolean hasWiredHeadset = (state == STATE_PLUGGED) ? true : false; switch (state) { case STATE_UNPLUGGED: updateAudioDeviceState(hasWiredHeadset); break; case STATE_PLUGGED: if (selectedAudioDevice != AudioDevice.WIRED_HEADSET) { updateAudioDeviceState(hasWiredHeadset); } break; default: Log.e(TAG, "Invalid state"); break; } } }; apprtcContext.registerReceiver(wiredHeadsetReceiver, filter); }
Example 14
Source File: HeadphoneIconData.java From Status with Apache License 2.0 | 4 votes |
@Override public IntentFilter getIntentFilter() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return new IntentFilter(AudioManager.ACTION_HEADSET_PLUG); else return new IntentFilter(Intent.ACTION_HEADSET_PLUG); }
Example 15
Source File: MusicService.java From Rey-MusicPlayer with Apache License 2.0 | 4 votes |
public void registerHeadsetPlugReceiver() { IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); mHeadsetPlugReceiver = new HeadsetPlugBroadcastReceiver(); mService.registerReceiver(mHeadsetPlugReceiver, filter); }
Example 16
Source File: PlayerService.java From IdealMedia with Apache License 2.0 | 4 votes |
@Override public void onCreate() { super.onCreate(); // initialize default output device if (!BASS.BASS_Init(-1, 44100, 0)) { return; } // look for plugins plugins = ""; String path = getApplicationInfo().nativeLibraryDir; String[] list = new File(path).list(); for (String s: list) { int plug = BASS.BASS_PluginLoad(path+"/"+s, 0); if (plug != 0) { // plugin loaded... plugins += s + "\n"; // add it to the list } } if (plugins.equals("")) plugins = "no plugins - visit the BASS webpage to get some\n"; if(playerInterface != null) { playerInterface.onPluginsLoaded(plugins); } BASS.BASS_SetConfig(BASS.BASS_CONFIG_BUFFER, 1000); Log.w("BASS.BASS_CONFIG_BUFFER", "" + BASS.BASS_GetConfig(BASS.BASS_CONFIG_BUFFER)); // Pending Intend Intent intent = new Intent(this, NavigationActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); pendIntent = PendingIntent.getActivity(this, 0, intent, 0); //tracklist loadTracks(); loadEqualizerValues(); tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm.listen(telephone, PhoneStateListener.LISTEN_CALL_STATE); myBroadcastReceiver = new ServiceBroadcastReceiver(); IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); intentFilter.addAction("android.media.VOLUME_CHANGED_ACTION"); intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); registerReceiver(myBroadcastReceiver, intentFilter); ComponentName rcvMedia = new ComponentName(getPackageName(), MediaControlReceiver.class.getName()); mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); mAudioManager.registerMediaButtonEventReceiver(rcvMedia); // Use the remote control APIs (if available) to set the playback state if (Build.VERSION.SDK_INT >= 14 && remoteControlClient == null) { registerRemoteControl(rcvMedia); } }
Example 17
Source File: AppRTCAudioManager.java From sealrtc-android with MIT License | 4 votes |
/** * Registers receiver for the broadcasted intent when a wired headset is plugged in or * unplugged. The received intent will have an extra 'state' value where 0 means unplugged, and * 1 means plugged. */ private void registerForWiredHeadsetIntentBroadcast() { IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); /** Receiver which handles changes in wired headset availability. */ wiredHeadsetReceiver = new BroadcastReceiver() { private static final int STATE_UNPLUGGED = 0; private static final int STATE_PLUGGED = 1; private static final int HAS_NO_MIC = 0; private static final int HAS_MIC = 1; @Override public void onReceive(Context context, Intent intent) { if (BluetoothUtil.hasBluetoothA2dpConnected()) return; int state = intent.getIntExtra("state", STATE_UNPLUGGED); int microphone = intent.getIntExtra("microphone", HAS_NO_MIC); String name = intent.getStringExtra("name"); Log.d( TAG, "BroadcastReceiver.onReceive" + AppRTCUtils.getThreadInfo() + ": " + "a=" + intent.getAction() + ", s=" + (state == STATE_UNPLUGGED ? "unplugged" : "plugged") + ", m=" + (microphone == HAS_MIC ? "mic" : "no mic") + ", n=" + name + ", sb=" + isInitialStickyBroadcast()); boolean hasWiredHeadset = (state == STATE_PLUGGED) ? true : false; switch (state) { case STATE_UNPLUGGED: updateAudioDeviceState(hasWiredHeadset); audioManager.setSpeakerphoneOn(isCurrentSpeakerOn); break; case STATE_PLUGGED: if (selectedAudioDevice != AudioDevice.WIRED_HEADSET) { updateAudioDeviceState(hasWiredHeadset); } break; default: Log.e(TAG, "Invalid state"); break; } } }; if (apprtcContext != null) { apprtcContext.registerReceiver(wiredHeadsetReceiver, filter); } }
Example 18
Source File: HeadsetPlugReceiver.java From Augendiagnose with GNU General Public License v2.0 | 2 votes |
/** * Register this receiver. * * @param context The context * @param handler A handler for headset plug events */ public void register(final Context context, final HeadsetPlugHandler handler) { mHandler = handler; IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); context.registerReceiver(this, intentFilter); }