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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:45:49+00:00 2026-06-17T14:45:49+00:00

I am using Eclipse and I have installed the app in my Android phone.

  • 0

I am using Eclipse and I have installed the app in my Android phone.

Main Activity Code :

package com.example.usbdetection;

 import android.app.Activity;
 import android.app.PendingIntent;
import android.content.BroadcastReceiver;
 import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
 import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
 import android.os.Bundle;
 import android.util.Log;

public class MainActivity extends Activity {



UsbManager usbManager;
    PendingIntent mPermissionIntent;
    UsbDevice usbDevice;
    Intent intent;
    final String ACTION_USB_PERMISSION = "com.example.usbdetection.USB_PERMISSION";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
        mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(
                ACTION_USB_PERMISSION), 0);

        IntentFilter filter = new IntentFilter();
        filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
        filter.addAction(ACTION_USB_PERMISSION);
        registerReceiver(mUsbReceiver, filter);
    }

private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
        if (ACTION_USB_PERMISSION.equals(action)) {
            synchronized (this) {

                usbDevice = (UsbDevice) intent
                        .getParcelableExtra(UsbManager.EXTRA_DEVICE);
                usbManager.requestPermission(usbDevice, mPermissionIntent);

                if (intent.getBooleanExtra(
                        UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                    if (usbDevice != null) {
                        // call method to set up device communication

                        int deviceId = usbDevice.getDeviceId();
                        int productId = usbDevice.getProductId();
                        Log.i("device id", "****" + deviceId);
                        Log.i("product id", "****" + productId);

                    } else {
                        Log.i("device id", "No USB device");
                    }

                } else {
                    Log.d("shiv", "permission denied for device ");
                }
            }
        }
    }
};

}

Manifest file :

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

<uses-sdk
    android:minSdkVersion="12"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.usbdetection.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
        </intent-filter>

        <meta-data
            android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
            android:resource="@xml/device_filter" />
    </activity>
</application>

When I run my app and connect any USB it shows nothing. whats wrong?.

Any help would be appreciated 🙂

  • 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-17T14:45:51+00:00Added an answer on June 17, 2026 at 2:45 pm

    I have found the solution:

    First i rooted my android device.
    and then i added a file named android.hardware.usb.host.xml in etc/permissions Folder which include permission

     <permissions>
     <feature name="android.hardware.usb.host" /> 
     </permissions>
    

    And now it supports Host API.

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

Sidebar

Related Questions

I have been using Eclipse to compile and run my development Android app. Now
I have created an Android App using Eclipse. I can't upload it to Android
I have the latest android ndk installed. I am using Eclipse along with Sequoyah.
I have written an Android app (target 3.2) using Eclipse 3.7, I tried to
I have installed MyEclipse 9.1 (installed from pulse using Eclipse Helios) and I need
I'm using Eclipse Carbon now and I have some installed Plugins. How to move
I am using Windows Vista 32bit . I have installed Eclipse Helios Service Release
I'm using Eclipse EE 3.7 with m2e plugin installed. I have JDK7 set in
I am developing an Android app on my Windows 7 Home PC using Eclipse.
This is a very interesting thing. I have an APK file, com.company.app.apk. When installed

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.