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

  • Home
  • SEARCH
  • 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 6095297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:47:46+00:00 2026-05-23T12:47:46+00:00

I know about using registerReceiver and unregisterReceiver in Java code for dealing with receivers,

  • 0

I know about using registerReceiver and unregisterReceiver in Java code for dealing with receivers, but let’s say I have the following in my manifest:

    <receiver android:name=".headsetHook">
        <intent-filter android:priority="99999999999">
            <action android:name="android.intent.action.ACTION_HEADSET_PLUG" />
        </intent-filter>
    </receiver>

Is there a way I could unregister this somewhere in Java code? Could I give it an id attribute or something and then get it and unregister it? I ask because I want my app to do something only on the first time this action happens, then unregister it and re-register it later in Java.

Hope I made that clear, thanks for any help.

  • 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-05-23T12:47:47+00:00Added an answer on May 23, 2026 at 12:47 pm

    You can use the PackageManager to enable/disable a BroadcastReceiver in declared in the Manifest. The Broadcast Receiver will get fired only when it is enabled.

    Use this to create a Component

    ComponentName component = new ComponentName(context, MyReceiver.class);
    

    Check if the Component is enabled or disabled

    int status = context.getPackageManager().getComponentEnabledSetting(component);
    if(status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
        Log.d("receiver is enabled");
    } else if(status == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
        Log.d("receiver is disabled");
    }
    

    Enable/Disable the component(Broadcast Receiver in your case)

    //Disable
    context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED , PackageManager.DONT_KILL_APP);
    //Enable
    context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED , PackageManager.DONT_KILL_APP);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very bad feeling about using lock in my code but now
I know about specifying source locations using gdb. But I am wondering if there's
Does anyone know any good tutorial about using NAnt for native code build process
I have a little problem about using jQuery (I really do not know jQuery
I know about using setEditing: to enable the editing mode of UITableView. But I
I know about using _ instead of & , but I'm looking at all
I know about using a -vsdoc.js file for IntelliSense , and the one for
I'd like know what people think about using RAISERROR in stored procedures to pass
Does anyone know a good online resource about using SQL Server 2005 dependency cache
I know about map/reduce alghoritm and its use. It's using functions that are called

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.