Doing Something If It Detects That Headphones Are Plugged In
Solution 1:
Add a <receiver>
in your manifest that listens for the ACTION_HEADSET_PLUG
broadcast.
The documentation shows Intent
extras that you can use to find out if the headset is plugged in (state
), etc.
Solution 2:
I think your question might have some duplicates:
The method you want seems to have be deprecated in API level 14. The documentation says to use it only to check whether the headset it connected or not. So for your purposes, that will fit. However, to check whether audio is being played though it, you might need a different solution.
From your comment, it looks like you want to know how to actually use it. The function returns true or false to put it in an if statement as the argument and you'll be set.
Solution 3:
I would set the BroadcastReceiver
to get the android.intent.action.HEADSET_PLUG
intent http://developer.android.com/reference/android/content/Intent.html#ACTION_HEADSET_PLUG
Solution 4:
I found the solution.
AudioManager audio=(AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
if(audio.isWiredHeadsetOn()){
Toast.makeText(this,"Headset is Connected",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this,"Headset is Not Connected",Toast.LENGTH_SHORT).show();
}
Thanks guys!
Post a Comment for "Doing Something If It Detects That Headphones Are Plugged In"