OS - Android: Difference between revisions

From Phidgets Support
No edit summary
 
(67 intermediate revisions by 7 users not shown)
Line 1: Line 1:
<metadesc>Communicate over USB with sensors, controllers and relays with Phidgets! Program in Android using Android Java.</metadesc>
[[Category:OS]]
[[Category:OS]]
{|
|style="vertical-align:middle; width: 60%;"|
==Getting Started with Android==
Welcome to using Phidgets with Android!


[[File:Icon-Android.png‎|64x64px|link=]] Android is a mobile OS commonly used on smartphones and tablet computers.  
If this is your first Phidget, we highly recommend working through the Getting Started guide for your specific Phidget device, which may be found in its [[:Category:UserGuide|user guide]]. If you are ready to go, the first step to creating an Android application with Phidgets is downloading the Phidget libraries on your development machine!
|{{TOC limit|2}}
|}
==Download==
The Phidget libraries for Android development are available here:
*[https://cdn.phidgets.com/downloads/phidget22/libraries/android/phidget22-android.zip Android Java Libraries]


__TOC__
Download and unpack the libraries. You will need to reference these files from your project in order to use Phidgets. This step is covered in detail in the [[Language - Android Java | Android Java page]]. If you need to access older versions of the libraries, [https://www.phidgets.com/downloads/phidget22/libraries/android/ click here].


Tablets with a USB port and Android version 3.1 or greater can control Phidgets directly plugged in to them. Earlier Android versions (tested down to 2.1) can control Phidgets over a network using the [[#Webservice|Webservice]].
==Direct USB Connection==
For directly controlling a Phidget with your Android device (i.e. plugging a Phidget directly into your device), you will need to ensure the device is capable of being a USB host. Just having a port that the USB cable can fit into does not necessarily indicate that the port can host a USB device. On the other hand, some phones can use an OTG (on-the-go) cable to allow plugging USB devices into their charging port. Some tablets (like the Samsung Galaxy Tab, for example) have the large 30-pin connectors that can be changed into a USB host using an adapter.


==Getting Started (Libraries and Drivers)==
The best way to know before getting your hands on a device is to check its specifications for whether it can serve as a USB host. Alternately, a quick way to figure out if your device can serve as a USB host is to try plugging other devices (such as a mouse, or USB memory stick) into your Android device.


If this is your first Phidget, we highly recommend working through the Getting Started guide [[Device List|for your specific Phidget device]].  
==Network Server==
In applications where you aren't plugging Phidgets into your Android device directly, you must have a host computer that is running the Phidget Network Server.  


Android code is developed on an external platform anyway (i.e. Windows, Mac OS, or Linux), and so getting your Phidget to work locally on that platform first will help you distinguish any issues from network ones later. 
[[Image:android-connection.jpg|link=|center]]


Near the end of the Windows, Mac OS, or Linux setup process, we direct you to choose a language.   At that point, please remember to return here to this Android Java page.
*Host computer: the computer that is physically connected to the Phidgets via USB and is running the Phidget Network Server.
*Client computer: a computer running a Phidgets application that accesses Phidgets connected to the host computer. When developing for Android, your Android device acts as the client.


Alternately, you can first try using [[Language - Java|mainstream Java]].  On the mainstream Java page, we provide example code - including code that works on the Android development platform of Eclipse - to test your Phidget directly from your development computer. 


===Installing===
In this case, you will need to install the Phidget libraries on your host computer, and get the Phidget Network Server up and running. Follow the ''Getting Started'' guide, and continue with the ''Network Server'' guide for your operating system. When you are done, come back and finish this guide!
 
*[[OS - Windows| Windows]]
 
*[[OS - OS X| macOS]]
 
*[[OS - Linux| Linux]]
====Eclipse (Android Java Development Platform)====
*[[OS - Phidget SBC| Phidget Single Board Computer]]
 
Development for your Android OS Phidget application can occur on Linux, Mac OSX, or Windows.  We recommend using Eclipse so you can run our provided Phidget examples.
 
You will need the following:
 
# The JDK and Java on your development system
#*See the [[Language - Java|mainstream Java]] page for details on Java for Windows, Mac, and Linux
# Eclipse (a Java Integrated Development Environment) on your development system
#*[http://www.eclipse.org/downloads/ http://www.eclipse.org/downloads/] (for Windows or MacOS)
#*<code>sudo apt-get install eclipse</code> (for Linux)
#*For 64-bit Linux, you will need the <code>ia32-libs</code> package as well, try:
#*:{{Code|sudo apt-get install ia32-libs}}
 
====Android SDK (and ADT Eclipse Plugin)====
 
After installing Java and Eclipse, you can install the Software Developer's Toolkit (SDK) and the plugin for Eclipse (ADT).
 
# Download and install the Android SDK package for your development system:
#*See the download instructions link at [http://developer.android.com/sdk/ http://developer.android.com/sdk/]
#*Google's instructions for installing are here: [http://developer.android.com/sdk/installing.html http://developer.android.com/sdk/installing.html]
# Download and install the ADT Eclipse Plugin for Android
#*Follow the instructions at [http://developer.android.com/sdk/eclipse-adt.html http://developer.android.com/sdk/eclipse-adt.html]
 
To check that the JDK, the Android SDK, and Eclipse have all been configured correctly, use the Google HelloAndroid example:
 
[http://developer.android.com/resources/tutorials/hello-world.html http://developer.android.com/resources/tutorials/hello-world.html]
 
Once you have confirmed that the Android SDK has been correctly installed, you are ready to begin developing applications with the [[Language - Android Java | Android Java]] libraries and language.
 
=====Android SDK and ADT on Linux=====
 
Run the Android SDK manager.  If {{Code|android-sdk-linux}} is the unpacked directory that was downloaded, try:
 
:{{Code|android-sdk-linux/tools/android}}
 
This will give you the option to download the Android versions you want to support.  Running the SDK from within Eclipse ({{Code|Window}} &rarr; {{Code|Android SDK}}) will let you add those Android versions to Eclipse, for emulating them before downloading to an Android device and using with Phidgets.
 
Then, to add Android support to Eclipse, first make sure {{Code|adb}} is in your path (e.g. by adding it to {{Code|/etc/environment}}
 
====Phidget Libraries====
 
The library {{Code|phidget21.jar}} from the '''Android examples''' (not the mainstream Java examples, despite the same name) are the libraries for including with your Android code.  You can download the examples and extract it specifically if needed:
 
*[http://www.phidgets.com/downloads/examples/android-examples_2.1.8.20120216.tar.gz http://www.phidgets.com/downloads/examples/android-examples_2.1.8.20120216.tar.gz]
 
When you download and unzip the Phidget Library for Android, it will contain three things:
 
# A libs/ folder
# A jar file containing the general Phidget java library (phidget21.jar)
# A jar file for directly driving USB devices from a USB port on the Android device (PhidgetsUSB.jar)
 
Feel free to browse around to get a sense of what will be going on the Android OS side.  We describe how to link and use this library later on the [[Language - Android Java#Write Your Own Code | Write your own Android code]] section of the Android Java page.
 
First, though, it will be useful to check to make sure Phidgets work with your Android system.
 
 
===Checking===
 
====Software====
 
The first way to see whether your libraries are set up correctly on
 
====Hardware====
 
Unfortunately, Android does not provide a way for the user to check whether a USB device is properly connected to a tablet.  The best way to check that any Phidget hardware is connected would be to run our [[Language - Android Java#Android 3.1+ with USB Port|Hello World USB example]].
 
If it doesn't work make sure that other devices that are supposed to work with your tablet (USB data keys, keyboards, etc. - the list depending entirely on which tablet) do indeed work. 
 
====Troubleshooting====


==Programming Languages==
==Programming Languages==


Android OS programs are written in [[Language - Android Java|Android Java]] using the Android SDK and the Phidgets library.
Now that you have the basics set up, check out the [[Language - Android Java|Android Java]] page for information on how to write code for Phidgets to run on your Android device.
 
Note that Android Java is NOT the same as mainstream Java.  Any Java programs you have will probably need significant modification before they run on Android, including our [[Language - Java|mainstream Java]] Phidget Examples
 
==Webservice==
 
===Setting Up the Webservice===
 
===Using the Webservice===
 
==Advanced Uses==
 
 


Note that Android Java is NOT the same as mainstream Java.  Any Java programs you have will probably need significant modification before they run on Android, including our [[Language - Java|mainstream Java]] Phidget Examples.
<!--
==Common Problems and Solutions==
==Common Problems and Solutions==
 
-->
If you are having trouble, ensure your Phidget libraries are ''up to date''.

Latest revision as of 22:03, 17 October 2023

Getting Started with Android

Welcome to using Phidgets with Android!

If this is your first Phidget, we highly recommend working through the Getting Started guide for your specific Phidget device, which may be found in its user guide. If you are ready to go, the first step to creating an Android application with Phidgets is downloading the Phidget libraries on your development machine!

Download

The Phidget libraries for Android development are available here:

Download and unpack the libraries. You will need to reference these files from your project in order to use Phidgets. This step is covered in detail in the Android Java page. If you need to access older versions of the libraries, click here.

Direct USB Connection

For directly controlling a Phidget with your Android device (i.e. plugging a Phidget directly into your device), you will need to ensure the device is capable of being a USB host. Just having a port that the USB cable can fit into does not necessarily indicate that the port can host a USB device. On the other hand, some phones can use an OTG (on-the-go) cable to allow plugging USB devices into their charging port. Some tablets (like the Samsung Galaxy Tab, for example) have the large 30-pin connectors that can be changed into a USB host using an adapter.

The best way to know before getting your hands on a device is to check its specifications for whether it can serve as a USB host. Alternately, a quick way to figure out if your device can serve as a USB host is to try plugging other devices (such as a mouse, or USB memory stick) into your Android device.

Network Server

In applications where you aren't plugging Phidgets into your Android device directly, you must have a host computer that is running the Phidget Network Server.

Android-connection.jpg
  • Host computer: the computer that is physically connected to the Phidgets via USB and is running the Phidget Network Server.
  • Client computer: a computer running a Phidgets application that accesses Phidgets connected to the host computer. When developing for Android, your Android device acts as the client.


In this case, you will need to install the Phidget libraries on your host computer, and get the Phidget Network Server up and running. Follow the Getting Started guide, and continue with the Network Server guide for your operating system. When you are done, come back and finish this guide!

Programming Languages

Now that you have the basics set up, check out the Android Java page for information on how to write code for Phidgets to run on your Android device.

Note that Android Java is NOT the same as mainstream Java. Any Java programs you have will probably need significant modification before they run on Android, including our mainstream Java Phidget Examples.