Java Code Examples for android.content.Intent.ACTION_HEADSET_PLUG

The following are Jave code examples for showing how to use ACTION_HEADSET_PLUG of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PeSanKita-android   File: WebRtcCallService.java   View Source Code Vote up 7 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 2
Project: Cable-Android   File: WebRtcCallService.java   View Source Code Vote up 7 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
Project: RetroMusicPlayer   File: MusicService.java   View Source Code Vote up 7 votes
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action != null) {
        switch (action) {
            case Intent.ACTION_HEADSET_PLUG:
                int state = intent.getIntExtra("state", -1);
                switch (state) {
                    case 0:
                        Log.d(TAG, "Headset unplugged");
                        pause();
                        break;
                    case 1:
                        Log.d(TAG, "Headset plugged");
                        play();
                        break;
                }
                break;
        }
    }
}
 
Example 4
Project: phonk   File: PMedia.java   View Source Code Vote up 6 votes
public void onHeadsetConnection(ReturnInterface callbackfn) {
    headsetCallbackfn = callbackfn;

    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    headsetPluggedReceiver = new HeadSetReceiver();
    getContext().registerReceiver(headsetPluggedReceiver, filter);
}
 
Example 5
Project: MusicX-music-player   File: MusicXService.java   View Source Code Vote up 6 votes
@Override
public void headsetState() {
    if (headsetListener != null) {
        IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
        registerReceiver(headsetListener, receiverFilter);
    }
}
 
Example 6
Project: EarPhoneKeySet   File: Methods.java   View Source Code Vote up 5 votes
static boolean isHeadSetUse(Context ctx) {
    IntentFilter iFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    Intent iStatus = ctx.registerReceiver(null, iFilter);
    return (iStatus != null ? iStatus.getIntExtra("state", 0) : 0) == 1;
}
 
Example 7
Project: IdealMedia   File: PlayerService.java   View Source Code Vote up 5 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 8
Project: Rey-MusicPlayer   File: MusicService.java   View Source Code Vote up 5 votes
public void registerHeadsetPlugReceiver() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    mHeadsetPlugReceiver = new HeadsetPlugBroadcastReceiver();
    mService.registerReceiver(mHeadsetPlugReceiver, filter);
}