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 8945667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:18:06+00:00 2026-06-15T12:18:06+00:00

I’m in ICS and am attempting to get a receiver attached that will be

  • 0

I’m in ICS and am attempting to get a receiver attached that will be called when a USB device and/or accessory is plugged in/out of the tablet.

Based on the documentation and other Stack questions, it *looks like all I should need is the code beneath, however when I run this code nothing happens… it’s hard to tell, cause my device has the USB accessory being plugged into/out of it, so my debugging is just me writing stuff to file, rather than actual debugging, but it doesn’t *appear to do anything at all.

  IntentFilter attachFilter = new IntentFilter();
  attachFilter.addAction(ACTION_USB_PERMISSION);
  attachFilter.addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);     
  registerReceiver(mAttachReceiver, attachFilter);

  IntentFilter detachFilter = new IntentFilter();
  detachFilter.addAction(ACTION_USB_PERMISSION);
  detachFilter.addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
  registerReceiver(mDetachedReceiver, detachFilter);

the receivers look like this (I’ve cut them down for brevity but they’re valid receivers)…

private final BroadcastReceiver mAttachReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        logMsg("ACTION = " + action);
        ... }

}

And my manifest contains this entry:

<uses-feature android:name="android.hardware.usb.host" />

Is there something I’m missing? I’ve tried ACTION_USB_DEVICE_ATTACHED instead of ACCESSORY but that doesn’t seem to produce any different results. Also, I CAN talk to the device in the app once its attached, so, it’s being recognized and the subsequent code that sends/receives messages from the attached device (it’s a NFC card reader) works as expected. The only thing that is persistently failing is the notification of the initial cable connection.

TIA

  • 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-15T12:18:08+00:00Added an answer on June 15, 2026 at 12:18 pm

    ACTION_USB_DEVICE_ATTACHED can only be a intent filter for an Activity and not a BroadCastReciever.

    The UsbManager only resolves activities(neither service not BroadcastReciever) and launches them.

    So you are not recieving any broadcast.

    Edit:
    Android Developer site does say its a broadcast, but Android Source is only resolving activities.
    Though you can use ACTION_USB_ACCESSORY_DETACHED for detach updates in reciever

    Edit2:
    There is nothing wrong in your code as far as Receiver is concerned. Your code is not working due to the way in which USB_ACCESSORY_ATTACHED is broadcast. The USB_ACCESSORY_ATTACHED is not a broadcast in true sense, Android Frameworks only launches the intent for activities, so you are not receiving the intent in broadcast Receiver.

    You can only use Activity for ATTACHED Intent and not receiver

    <activity android:name=".YourActivity" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
        </intent-filter>
    
        <meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
                   android:resource="@xml/accessory_filter" />
    </activity>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.