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.

    Cracked Accounts Free Netflix Accounts VPN Proxy Shares Hack Programları Hack dökümanları Hack methodsları Wordlist Combolist Warez Scriptler Download Warez Files WhatsApp Numara çekme +90 Abazalardan Para kazanma Telegram Mavi tik alma 2022 Numara sorgulama Azuere Aws Sanal Kart Method WhatsApp vurma Güncel Method 2022 Bedava .Com .Org .Net VDS Premium Host YouTube Sahte Telif Methodu Tıklama hilesi ile para kazanmak Azure Hack method Pubg Mobile Uc Almak Hedef Kişinin herşeyini öğrenmek instagram Telif taslağı 2022 Ölüm Belgesi ile instagram hesap kaptma instagram form ile ebedi hesap kapatma instagram taklitsiz hesap kapatma instagram Çift faktör geçme instagram tiktok hesap çalma method instagram 2 Faktörlü doğrulama geçme instagram hesap kapatma 2022 instagram rever kırmak instagram Revert Kırma Abaza Dayı Methodu Aylık Dolar kazamak 1500 dolar instagram Çalmak istiyorum instagram düşmeyen takipçi instagram hackleme sitesi Whatsapp Kapatma %100 Abaza tokatlayarak para kazanmak Spotify ile para kazanma Günde 100 tl kazanma sınırsız kazanç Yatakta yatarak para kazanma YouTube izlenme arttırme yöntemi Oturduğun yerde para kazanma yöntemi Discord Hack tool Discord hack programları Cerebrus Rat v2 kodları PP Takipçi Çeken Telif Scripti Facebook profil kapatma methodu 2022 instagram yapay ile banned methodu instagram hesap satşı Sosyal medya hesap satışı Sosyal medya hack Leak Forum Crack Forum Cracking Forum Warez Forum Hack Forum illegal Forum Hacking Forum instagram Forum instagram Forumu Hacklink Hack forum php Shell indir Hack haber nakliyatankara nakliyatistanbul nakliyatankara nakliyatJigolodiyarijigolo sitesigerçek jigolo sitesijigolo sitelerimjigolo şirketlerijigolo sitelerijigolo başvurujigolo arayan kadınlara ulaşKocuceKo cuce