USB communication between Android (accessory mode) and Windows PC (host)

how to enable usb host mode on android
usb host mode vs device mode
android usb permission
android auto usb accessory mode
usb host mode android
android usb accessories
android usb architecture
usb logging control android

I try to make an USB connection between my notebook (win7) and my android phone (Android 4.2). The notebook should act as host to power the android phone. The goal is that notebook and phone can send and receive xml strings

I tried to follow the the android page that explains accessory mode (http://developer.android.com/guide/topics/connectivity/usb/accessory.html).

  • 1: Must I define a accessory filter like they did here:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <usb-accessory model="DemoKit" manufacturer="Google" version="1.0"/>
    </resources>
    

    Because I don't want a special hardware to be recognized. I want all kind of windows computers to be recognized (e.g. I plug the phone in another pc).

  • 2: I've done nothing on the windows side right now. I just followd the android page, pluged in the usb cable and watched the log. The app startet asks for permission, but the accessory is null. Any hints why it is null? Code:

    public class MainActivity extends Activity {
    private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
    private static final String TAG = "USB_PERMISSION";
    UsbAccessory accessory;
    
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
    
    PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    registerReceiver(mUsbReceiver, filter);
    accessory = (UsbAccessory) getIntent().getParcelableExtra(
            UsbManager.EXTRA_ACCESSORY);
    manager.requestPermission(accessory, mPermissionIntent);
     }
    
    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) {
                if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                    String manufacturer;
                    Log.d(TAG, "permission accepted for accessory " + accessory);
                    if (accessory != null) {
                        manufacturer = accessory.getManufacturer();
                        Log.d(TAG, "Manufacturer: " + manufacturer);                        }
                } else {
                    Log.d(TAG, "permission denied for accessory "+ accessory);
                }
            }
        }
    }
    };
    }
    
  • 3: Are there any libarys/projects I can use to identify the USB connection on the Windows side?

  • 4: Any further things I should think about? Things that are wrong?
  • 5: thx for your help :)

You should have an application on the host side (Windows in your case) that will ask the Android to enter accessory mode. When it asks, you will be presented with the option to give permission or not. You have null accessory because there is no accessory connected, that has followed the AOAP to initiate a communication. So it is possible to have accessory device, that is not running Android and to communicate with it using AOAP.

You can find an example for the Android side in the samples from your android SDK, in USB folder.

USB host and accessory overview, Loaders � Recents screen � Multi-window support � Restrictions on starting In USB accessory mode, the external USB hardware act as the USB hosts. still interact with Android applications that can correctly communicate with the device. Connect the Android-powered device via USB to your computer. Figure 1 shows the differences between the two modes. When the Android-powered device is in host mode, it acts as the USB host and powers the bus. When the Android-powered device is in USB accessory mode, the connected USB hardware (an Android USB accessory in this case) acts as the host and powers the bus. Figure 1. USB Host and Accessory

Yeah, you need use WinUSB/libusb API in Windows side to do the host work, turn the Android into accessory mode, and then talk each other

USB accessory overview, When your Android-powered device is in USB host mode, it acts as the you to enumerate and communicate with connected USB devices. Figure 1 shows the differences between the two modes. When the Android-powered device is in host mode, it acts as the USB host and powers the bus. When the Android-powered device is in USB accessory mode, the connected USB hardware (an Android USB accessory in this case) acts as the host and powers the bus. Figure 1. USB Host and Accessory

The reason you got 0 accessory because you don't have accessory devices hooked to your Android USB port, you scenario is using Windows PC as the host (You may try write a customized WinUSB driver) and the Android device is a pure USB device, it has nothing to do with AOA, when you send mode switch request from host computer (Windows or macOS), the Android device turn into accessory mode and itself is an accessory, you will find one accessory by using getAccessoryList. BTW, I got both Windows and macOS working with Android via libusb.

USB host overview, In addition, some Android devices do not have the USB host hardware needed to support communications in USB host mode. The Android device generally has� Most Android devices run the ADB protocol in slave mode. Some also support "accessory mode" which is a variation of this. However neither of these would look like a "virtual com port" to the upstream host pc, and there is no API for changing this.

Ok, I guess I found the answer myself. The Android USB accessory mode is only possible between an android phone and another device that is running Android (such as Arduino). So this is not possible with this setting.

Develop AOA USB Accessories For Android-Based Systems , It standardizes the computer peripherals. Windows Mobile App Development Tutorial USB accessory and host modes are supported in Android 3.1 (API level 12) or In host mode android powered device acts as the USB host, powers the bus, and We need to have permission before communicating with USB device. When an Android-powered device is in USB accessory mode, the attached Android USB accessory acts as the host, provides power to the USB bus, and enumerates connected devices. Android 3.1 (API level 12) supports USB accessory mode and the feature is also backported to Android 2.3.4 (API level 10) to enable support for a broader range of devices.

Android and USB, allows an Android device to interact with an. Android USB accessory in a special accessory mode. • Basically there are four steps to initiate the communication. Accessory (AOA) to allow connection of a USB host device that follows the protocol. The USB Host / Peripheral relationship is maintained, however, the logical function of the connection is reversed. The Android device and USB Host use the AOA protocol to allow the Android device to have control over the USB host.

[PDF] Leveraging the Android Accessory Protocol, USB communication between Android (accessory mode) and Windows PC (host) . 发表于 2019-9-23 | | 暂无分类. I try to make an USB connection between my� 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. API Overview. Before you begin, it is important to understand the classes that you need to work with.

USB communication between Android (accessory mode , Beaglebone runs the Android USB accessory protocol with application u-boot has limited support for AM335x peripherals and we found USB Host protocol lack few Beaglebone can be communicate to Android phone using Google Cloud The phone can be connected to a Windows or Linux PC and the application can � Upon the successful connection of your Android phone to a computer, you have the option of configuring the USB connection. A menu appears, either automatically or when you choose the USB notification. If not, you can manually configure the USB connection by following these steps: Open the Settings app. Choose Storage. Touch the Action Overflow …

Comments
  • So I guess #1 is clearer now. Intentfilter is only needed for automatic deteciton
  • and how can it be achieved any source app?
  • Did you find any sample pc-side to receive data from android ?
  • @seed Actually I haven't used it. Once it was possible to start using it, so I got familiar with it, however it was deferred and I have not dealt with it since then. However I think that it should not be a big deal to figure it out, once you know the protocol.
  • @helleye you mean my app in android phone can actual respond to windows over USB? I had similar requirement earlier and i used adb in windows to communicate with my app and my app used to create text files on a predefined path from where my windows app would read file.
  • @Calvin Yes, this is what the accessory mode is about. You should follow the AOA protocol and you can start by reading source.android.com/devices/accessories/protocol.html
  • This answer is incorrect - an Arduino does not run Android, and there is no need for the USB host to do so. However, it does need to be able to talk in the specific ways required to support the USB accessory mode.