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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:17:41+00:00 2026-06-05T15:17:41+00:00

I’m a beginner android programmer who is trying to set up some USB functionality

  • 0

I’m a beginner android programmer who is trying to set up some USB functionality with my tablet and a device. My program uses an Intent filter to find the device. I took the Android’s MissileLauncherActivity.java example and rewrote it. I am getting a “could not find endpoint” error in logcat. Is there something wrong with my code, or could it be my device? LogCat is finding the error in the setDevice method where it is trying to find the OUT endpoint. Here is the code:

public class UsbTestActivity extends Activity implements Runnable {

private UsbManager mUsbManager;
private UsbDevice mDevice;
private UsbDeviceConnection mConnection;
private UsbEndpoint mEndpointIntr;
private static final String TAG = "UsbTestActivity";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
}

@Override
public void onPause(){
    super.onPause();
}

@Override
public void onResume(){
    super.onResume();

    Intent intent = getIntent();
    Log.d(TAG, "intent: " + intent);
    String action = intent.getAction();
    UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
        setDevice(device);
    } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
        if (mDevice != null && mDevice.equals(device)) {
            setDevice(null);
        }
    }
}

@Override
public void onDestroy() {
    super.onDestroy();
}

public void setDevice(UsbDevice device){
    Log.d(TAG, "setDevice " + device);
    if (device.getInterfaceCount() != 1) {
        Log.e(TAG, "could not find interface");
        return;
    }
    UsbInterface intf = device.getInterface(0);
    // device should have one endpoint
    if (intf.getEndpointCount() != 1) {
        Log.e(TAG, "could not find endpoint");
        return;
    }
    System.out.println("Got endpoint");
    // endpoint should be of type interrupt
    UsbEndpoint ep = intf.getEndpoint(0);
    if (ep.getType() != UsbConstants.USB_ENDPOINT_XFER_INT) {
        Log.e(TAG, "endpoint is not interrupt type");
        return;
    }
    mDevice = device;
    mEndpointIntr = ep;
    if (device != null) {
        UsbDeviceConnection connection = mUsbManager.openDevice(device);
        if (connection != null && connection.claimInterface(intf, true)) {
            Log.d(TAG, "open SUCCESS");
            mConnection = connection;
            Thread thread = new Thread(this);
            thread.start();

        } else {
            Log.d(TAG, "open FAIL");
            mConnection = null;
        }
     }
}


private void sendCommand(int control) {
    synchronized (this) {
        if (mConnection != null) {
            byte[] message = new byte[1];
            message[0] = (byte)control;
            // Send command via a control request on endpoint zero
            if(mConnection.controlTransfer(0x21, 0x9, 0x200, 0, message, message.length, 0) > 0){
                Log.d(TAG, "Sending Failed");
        }
    }
}
}

public void run() {
    ByteBuffer buffer = ByteBuffer.allocate(1);
    UsbRequest request = new UsbRequest();
    request.initialize(mConnection, mEndpointIntr);
    byte status = -1;
    while (true) {
        // queue a request on the interrupt endpoint
        request.queue(buffer, 1);
        // send poll status command
        if (mConnection.requestWait() == request) {
            byte newStatus = buffer.get(0);
            if (newStatus != status) {
                Log.d(TAG, "got status " + newStatus);
                status = newStatus;
                sendCommand(7);

            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
        } else {
            Log.e(TAG, "requestWait failed, exiting");
            break;
        }
    }
}

}
  • 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-05T15:17:43+00:00Added an answer on June 5, 2026 at 3:17 pm
    // device should have one endpoint
        if (intf.getEndpointCount() != 1) {
            Log.e(TAG, "could not find endpoint");
            return;
        }
    

    Looks like you are trying to work with a USB HID device and its OUT endpoint. But HID mandates the IN endpoint to be present – so getEndpointCount() will most likely return 2 instead of one. You will need to check which is the IN and which is OUT.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.