GithubHelp home page GithubHelp logo

linecode / androidusbtest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cnlohr/androidusbtest

0.0 1.0 0.0 31 KB

Access external devices from Android apps directly in C.

Makefile 2.76% C 97.24%

androidusbtest's Introduction

Using USB devices in apps on Android in C

This toolset uses rawdrawandroid: https://github.com/cnlohr/rawdrawandroid if you are curious how to develop C applications on Android, check that out.

This toolset operates as a copy-pastable demo of how to do USB in C apps on Android. This is not intended as catch-all or clean demo, but rather a minimal demonstration of getting permissions, and opening up USB devices in C on Android.

You can check out the hardware used for this here: https://github.com/cnlohr/tensigral_lamp

Cutting to the chase

There are three fundamental parts to using USB working on Android in C. Three out of the four of these are completely covered in the void RequestPermissionOrGetConnectionFD() function in test.c. You will need to do all of this in the JNI.

  1. You must iterate through the device list from UsbManager, with .getDeviceList() and find your device.
  2. You must request permission from Android to use the device with .requestPermission(); caveat: You can just try connecting, if you don't have permission it won't let you connect.
  3. You must claim the interface to the device with .claimInterface().
  4. You can then use bulk endpoint functions from Android, OR, even better! You can use .getFileDescriptor() and then perform ioctl operations on the file descriptor, sending and receiving data. Interrupt and bulk data is normal. It says you can even make control messages, though I haven't tried.

androidusbtest's People

Contributors

cnlohr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.