Android App for USB Host (with source code) – Mobile App Development, Android App Development, iphone App Development class="post-template-default single single-post postid-1580 single-format-standard wp-custom-logo"

Android App for USB Host (with source code)

Android App for USB Host (with source code)

Download APK Download Source Code Contact Us


When your Android-powered device is in USB host mode, it acts as the USB host, powers the bus, and enumerates connected USB devices. USB host mode is supported in Android 3.1 and higher.

Before you begin, it is important to understand the classes that you need to work with.

In most situations, you need to use all of these classes (UsbRequest is only required if you are doing asynchronous communication) when communicating with a USB device. In general, you obtain a UsbManager to retrieve the desired UsbDevice. When you have the device, you need to find the appropriate UsbInterface and the UsbEndpoint of that interface to communicate on. Once you obtain the correct endpoint, open aUsbDeviceConnection to communicate with the USB device.

Note:- In most of old phone USB hosting is not provided, only in new mobiles have inbuilt feature of USB Hosting. If you want to used it in old phones than you need to root your phone but it’s not advisable better you use USB Accessory in place of USB Host . it is similar to USB Host.

Here is a sample example to set USB Host in you android app
Layout Code: activity_main. Xml
When application is executed this is the first layout design that will run which will load width, height, load back ground details..etc.

[code lang=”js”]
<linearlayout xmlns:android=""
tools:context=".MainActivity" >

<button android:id="@+id/check"
android:text="Check USB devices"></button>
<textview android:id="@+id/info"


Java File : file in package com.mobilemerit.usbhost.
Main activity file will load design form like buttons, text view, on click functionality, display text.

[code lang=”js”]
package com.mobilemerit.usbhost;
import java.util.HashMap;
import java.util.Iterator;
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;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.mobilemerit.usbhost.R;

public class MainActivity extends Activity {
PendingIntent mPermissionIntent;
Button btnCheck;
TextView textInfo;
UsbDevice device;
UsbManager manager;
private static final String ACTION_USB_PERMISSION = "com.mobilemerit.usbhost.USB_PERMISSION";

protected void onCreate(Bundle savedInstanceState) {
btnCheck = (Button) findViewById(;
textInfo = (TextView) findViewById(;
btnCheck.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {


private void checkInfo() {
manager = (UsbManager) getSystemService(Context.USB_SERVICE);
* this block required if you need to communicate to USB devices it’s
* take permission to device
* if you want than you can set this to which device you want to communicate
// ——————————————————————
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter);
// ——————————————————————-
HashMap<string , UsbDevice> deviceList = manager.getDeviceList();
Iterator<usbdevice> deviceIterator = deviceList.values().iterator();
String i = "";
while (deviceIterator.hasNext()) {
device =;
manager.requestPermission(device, mPermissionIntent);
i += "\n" + "DeviceID: " + device.getDeviceId() + "\n"
+ "DeviceName: " + device.getDeviceName() + "\n"
+ "DeviceClass: " + device.getDeviceClass() + " – "
+ "DeviceSubClass: " + device.getDeviceSubclass() + "\n"
+ "VendorID: " + device.getVendorId() + "\n"
+ "ProductID: " + device.getProductId() + "\n";


private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {

public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice) intent
if (intent.getBooleanExtra(
if (device != null) {
// call method to set up device communication
} else {
Log.d("ERROR", "permission denied for device " + device);


This is the main configuration file for USB Host android project. This xml code will load required permission and main activity by default.

[code lang=”js”]
< ?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
android:versionName="1.0" >

<uses -feature android:name=""></uses>
<uses -sdk

<application android:allowBackup="true"
android:theme="@style/AppTheme" >
<activity android:name="com.mobilemerit.usbhost.MainActivity"
android:label="@string/app_name" >
<intent -filter>
<action android:name="android.intent.action.MAIN"></action>

<category android:name="android.intent.category.LAUNCHER"></category>


This is a simple code to find usb connected devices. If you need to communicate with usb device means send or receive data between your phone and usb device than you can other classes and interface (UsbInterface, UsbEndpoint, UsbDeviceConnection, UsbRequest).

Android App for USB Host
Android App for USB Host
Android App for USB Host

Download APK Download Source Code Contact Us

  • Warning: _() expects exactly 1 parameter, 2 given in /home2/mobilemeri7/public_html/wp-content/themes/mobilemerit/comments.php on line 28

    Write a Reply or Comment

    Your email address will not be published.

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Crack Accounts admin panel bypass Tiktok hackleme sitesi Nulled Scripts Nulled Script ioncube decoder iphone sızma valorant hackleme Crack script Brute force programı Brute force yapma internetten para kazanma Evde para kazanmanın yolları Öğrenciler için internetten para kazanma yolları valorant combo Brute force programı Açıklı siteler SQL Açıklı siteler CMS Brute Force kaçağı bulmasu tesisatçısıjigolo siteleri arkadaş bulankara nakliyatankara nakliyatistanbul nakliyatgay sohbetbatak oynatavla oynagabile sohbetokey oynaoyunlar oyna #yaslikurt# sex geschichten sex geschichten brazzers rot media instagram banned service Hack haber Hacklink satışı Hacklink Çift faktör kıran telif scripti instagram hackleme sitesi instagram hackleme sitesi Bahis scripti Hack sitesi Crack forum Crack forum Crack Crack Forum instagram hackleme sitesi instagram hesap kapatma instagram hesap kapatma formları instagram hesap kapatma method instagram faktör geçme instagram faktör kırma instagram telif scripti Instagram Telif Scripti 2022 instagram hackleme sitesi apili telif scripti Facebook Temalı Telif Scripti