Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8866815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:52:54+00:00 2026-06-14T16:52:54+00:00

I am working in Android 2.1, and I want to detect when the headset

  • 0

I am working in Android 2.1, and I want to detect when the headset is plugged in/taken out. I’m pretty new to android.

I think the way to do it is using a Broadcast receiver. I sublcassed this, and I also put the following in my AndroidManifest.xml. But do you have to register the receiver somehwere else, like in the activity? I’m aware there are lots of threads on this, but I don’t really understand what they’re talking about. Also, what’s the difference between registering in AndroidManifest.xml versus registering dynamically in your activity?

<receiver android:enabled="true" android:name="AudioJackReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.HEADSET_PLUG" >
            </action>
        </intent-filter>
    </receiver>

And this was the implementation of the class (plus imports)

public class AudioJackReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Log.w("DEBUG", "headset state received");
}

}

I was just trying to see if it works, but nothing shows up when I unplug/plug in the headset while running the application.

EDIT: the documentation doesn’t say this, but is it possible that this one won’t work if registered in the manifest? I was able to get it to respond when I registered the receiver in one of my applications (or do you have to do that anyway?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:52:55+00:00Added an answer on June 14, 2026 at 4:52 pm

    Here are two sites that may help explain it in more detail:

    • http://www.grokkingandroid.com/android-tutorial-broadcastreceiver/
    • http://www.vogella.com/articles/AndroidBroadcastReceiver/article.html

    You have to define your intent; otherwise it won’t access the system function. The broadcast receiver; will alert your application of changes that you’d like to listen for.

    Every receiver needs to be subclassed; it must include a onReceive(). To implement the onReceive() you’ll need to create a method that will include two items: Context & Intent.

    More then likely a service would be ideal; but you’ll create a service and define your context through it. In the context; you’ll define your intent.

    An example:

    context.startService
          (new Intent(context, YourService.class));
    

    Very basic example. However; your particular goal is to utilize a system-wide broadcast. You want your application to be notified of Intent.ACTION_HEADSET_PLUG.

    How to subscribe through manifest:

    <receiver
        android:name="AudioJackReceiver"
        android:enabled="true"
        android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.HEADSET_PLUG" />
        </intent-filter>
    </receiver>
    

    Or you can simply define through your application; but. Your particular request; will require user permissions if you intend to detect Bluetooth MODIFY_AUDIO_SETTINGS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in android. I want to create a chat room dynamically using
I am new to android and working on accelerometer. I want to collect 20
Currently I'm working on an app for Android phones. We want to detect features
I am working in android, I am using a button. Now I want to
I am currently working on android project where I want to have a text
I am working on android apps. I want to add a contact in android
I am working in an android application and I want to work fetch details
I am working in an android application and I want to implement a Gallery.
I am working on an android game. I want to copy a text file
I am working on one android app. I want to connect my local PC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.