├── USBComm
├── ReadMe.md
├── res
│ ├── drawable-hdpi
│ │ └── icon.png
│ ├── drawable-ldpi
│ │ └── icon.png
│ ├── drawable-mdpi
│ │ └── icon.png
│ ├── values
│ │ └── strings.xml
│ └── layout
│ │ └── main.xml
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ └── org.eclipse.ltk.core.refactoring.prefs
├── bin
│ ├── classes
│ │ └── com
│ │ │ └── demo
│ │ │ └── usb
│ │ │ ├── R.class
│ │ │ ├── R$id.class
│ │ │ ├── R$attr.class
│ │ │ ├── R$layout.class
│ │ │ ├── R$string.class
│ │ │ ├── BuildConfig.class
│ │ │ ├── R$drawable.class
│ │ │ ├── USBServerActivity$1.class
│ │ │ ├── USBServerActivity$2.class
│ │ │ └── USBServerActivity.class
│ └── AndroidManifest.xml
├── gen
│ └── com
│ │ └── demo
│ │ └── usb
│ │ ├── BuildConfig.java
│ │ └── R.java
├── .classpath
├── project.properties
├── AndroidManifest.xml
├── .project
├── proguard.cfg
└── src
│ └── com
│ └── demo
│ └── usb
│ └── USBServerActivity.java
├── USBClient
├── bin
│ └── USBClient.class
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
└── src
│ └── USBClient.java
└── ReadMe.txt
/USBComm/ReadMe.md:
--------------------------------------------------------------------------------
1 | Android USB Server
--------------------------------------------------------------------------------
/USBClient/bin/USBClient.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBClient/bin/USBClient.class
--------------------------------------------------------------------------------
/USBComm/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/USBComm/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/USBComm/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/USBComm/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/com/demo/usb/USBServerActivity.java=UTF-8
3 |
--------------------------------------------------------------------------------
/USBComm/bin/classes/com/demo/usb/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/bin/classes/com/demo/usb/R.class
--------------------------------------------------------------------------------
/USBComm/bin/classes/com/demo/usb/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/bin/classes/com/demo/usb/R$id.class
--------------------------------------------------------------------------------
/USBComm/bin/classes/com/demo/usb/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/bin/classes/com/demo/usb/R$attr.class
--------------------------------------------------------------------------------
/USBComm/bin/classes/com/demo/usb/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/bin/classes/com/demo/usb/R$layout.class
--------------------------------------------------------------------------------
/USBComm/bin/classes/com/demo/usb/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/bin/classes/com/demo/usb/R$string.class
--------------------------------------------------------------------------------
/USBComm/bin/classes/com/demo/usb/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/bin/classes/com/demo/usb/BuildConfig.class
--------------------------------------------------------------------------------
/USBComm/bin/classes/com/demo/usb/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/bin/classes/com/demo/usb/R$drawable.class
--------------------------------------------------------------------------------
/USBComm/bin/classes/com/demo/usb/USBServerActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/bin/classes/com/demo/usb/USBServerActivity$1.class
--------------------------------------------------------------------------------
/USBComm/bin/classes/com/demo/usb/USBServerActivity$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/bin/classes/com/demo/usb/USBServerActivity$2.class
--------------------------------------------------------------------------------
/USBComm/bin/classes/com/demo/usb/USBServerActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/user370305/Android-USB-Communication/HEAD/USBComm/bin/classes/com/demo/usb/USBServerActivity.class
--------------------------------------------------------------------------------
/USBComm/.settings/org.eclipse.ltk.core.refactoring.prefs:
--------------------------------------------------------------------------------
1 | #Mon Dec 26 16:16:39 IST 2011
2 | eclipse.preferences.version=1
3 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
4 |
--------------------------------------------------------------------------------
/USBComm/gen/com/demo/usb/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.demo.usb;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/ReadMe.txt:
--------------------------------------------------------------------------------
1 | Android application to communicate with host machine over USB.
2 |
3 | // Necessary step
4 |
5 | // make sure you have a done adb port forwarding before running this project using this step
6 |
7 | > adb forward tcp:38300 tcp:38300 // In your case port number may be different
--------------------------------------------------------------------------------
/USBComm/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/USBClient/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/USBComm/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World, USBCommActivity!
4 | USBComm
5 | To start connection press button:
6 | Start Connection
7 |
8 |
--------------------------------------------------------------------------------
/USBClient/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | USBClient
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/USBComm/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-4
15 |
--------------------------------------------------------------------------------
/USBClient/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Wed Nov 30 12:47:39 IST 2011
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=1.6
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.source=1.6
13 |
--------------------------------------------------------------------------------
/USBComm/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/USBComm/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/USBComm/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | USBComm
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/USBComm/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
25 |
26 |
--------------------------------------------------------------------------------
/USBComm/gen/com/demo/usb/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.demo.usb;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class drawable {
14 | public static final int icon=0x7f020000;
15 | }
16 | public static final class id {
17 | public static final int btnView=0x7f050002;
18 | public static final int tableLayout1=0x7f050000;
19 | public static final int textView=0x7f050001;
20 | }
21 | public static final class layout {
22 | public static final int main=0x7f030000;
23 | }
24 | public static final class string {
25 | public static final int app_name=0x7f040001;
26 | public static final int hello=0x7f040000;
27 | public static final int startbutton=0x7f040003;
28 | public static final int starttext=0x7f040002;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/USBComm/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembers class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembers class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers class * extends android.app.Activity {
30 | public void *(android.view.View);
31 | }
32 |
33 | -keepclassmembers enum * {
34 | public static **[] values();
35 | public static ** valueOf(java.lang.String);
36 | }
37 |
38 | -keep class * implements android.os.Parcelable {
39 | public static final android.os.Parcelable$Creator *;
40 | }
41 |
--------------------------------------------------------------------------------
/USBClient/src/USBClient.java:
--------------------------------------------------------------------------------
1 | import java.io.IOException;
2 | import java.io.ObjectInputStream;
3 | import java.io.ObjectOutputStream;
4 | import java.net.Socket;
5 | import java.net.UnknownHostException;
6 |
7 | public class USBClient
8 | {
9 | public static void main(String[] args) throws IOException
10 | {
11 | Socket echoSocket = null;
12 | ObjectOutputStream out = null;
13 | ObjectInputStream in = null;
14 | String message = "";
15 |
16 | // Create socket connection with host address as localhost and port number with 38300
17 | try
18 | {
19 | echoSocket = new Socket("localhost", 38300);
20 | out = new ObjectOutputStream(echoSocket.getOutputStream());
21 | out.flush();
22 | in = new ObjectInputStream(echoSocket.getInputStream());
23 |
24 | // Communicating with the server
25 | try
26 | {
27 | message = (String) in.readObject();
28 | System.out.println("server>" + message);
29 | }
30 | catch (ClassNotFoundException classNot)
31 | {
32 | System.err.println("data received in unknown format");
33 | }
34 | }
35 | catch (UnknownHostException e)
36 | {
37 | System.err.println("Don't know about host: LocalHost.");
38 | System.exit(1);
39 | }
40 | catch (IOException e)
41 | {
42 | System.err.println("Couldn't get I/O for " + "the connection to: LocalHost:");
43 | System.exit(1);
44 | }
45 | finally
46 | {
47 | // Closing connection
48 | try
49 | {
50 | in.close();
51 | out.close();
52 | if (echoSocket != null)
53 | {
54 | echoSocket.close();
55 | }
56 | }
57 | catch (IOException ioException)
58 | {
59 | ioException.printStackTrace();
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/USBComm/src/com/demo/usb/USBServerActivity.java:
--------------------------------------------------------------------------------
1 | package com.demo.usb;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.ObjectOutputStream;
6 | import java.net.ServerSocket;
7 | import java.net.Socket;
8 | import java.net.SocketTimeoutException;
9 |
10 | import android.app.Activity;
11 | import android.os.Bundle;
12 | import android.os.Handler;
13 | import android.util.Log;
14 | import android.view.View;
15 | import android.view.View.OnClickListener;
16 | import android.widget.Button;
17 | import android.widget.Toast;
18 |
19 | public class USBServerActivity extends Activity implements OnClickListener
20 | {
21 |
22 | public static final String TAG = "USBCommActivity";
23 | public static final int TIMEOUT = 10;
24 | private Button btnStartServer;
25 | private String connectionStatus = null;
26 | private final String sendMsg = "Hello From Server";
27 | private Handler mHandler = null;
28 | private ServerSocket server = null;
29 | private Socket client = null;
30 | private ObjectOutputStream out;
31 | public static InputStream nis = null;
32 |
33 | @Override
34 | public void onCreate(Bundle savedInstanceState)
35 | {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.main);
38 |
39 | btnStartServer = (Button) findViewById(R.id.btnView);
40 | btnStartServer.setOnClickListener(this);
41 | mHandler = new Handler();
42 | }
43 |
44 | /**
45 | * Thread to initialize Socket connection
46 | */
47 | private final Runnable initializeConnection = new Thread()
48 | {
49 | @Override
50 | public void run()
51 | {
52 | // initialize server socket
53 | try
54 | {
55 | server = new ServerSocket(38300);
56 | server.setSoTimeout(USBServerActivity.TIMEOUT * 1000);
57 |
58 | //attempt to accept a connection
59 | client = server.accept();
60 |
61 | out = new ObjectOutputStream(client.getOutputStream());
62 | USBServerActivity.nis = client.getInputStream();
63 | try
64 | {
65 | out.writeObject(sendMsg);
66 | System.out.println("client >" + sendMsg);
67 |
68 | byte[] bytes = new byte[1024];
69 | int numRead = 0;
70 | while ((numRead = USBServerActivity.nis.read(bytes)) >= 0)
71 | {
72 | connectionStatus = new String(bytes, 0, numRead);
73 | mHandler.post(showConnectionStatus);
74 | }
75 | }
76 | catch (IOException ioException)
77 | {
78 | Log.e(USBServerActivity.TAG, "" + ioException);
79 | }
80 | }
81 | catch (SocketTimeoutException e)
82 | {
83 | connectionStatus = "Connection has timed out! Please try again";
84 | mHandler.post(showConnectionStatus);
85 | }
86 | catch (IOException e)
87 | {
88 | Log.e(USBServerActivity.TAG, "" + e);
89 | }
90 |
91 | if (client != null)
92 | {
93 | connectionStatus = "Connection was succesful!";
94 | mHandler.post(showConnectionStatus);
95 | }
96 | }
97 | };
98 |
99 | /**
100 | * Runnable to show pop-up for connection status
101 | */
102 | private final Runnable showConnectionStatus = new Runnable()
103 | {
104 | //----------------------------------------
105 | /**
106 | * @see java.lang.Runnable#run()
107 | */
108 | //----------------------------------------
109 | @Override
110 | public void run()
111 | {
112 | Toast.makeText(USBServerActivity.this, connectionStatus, Toast.LENGTH_SHORT).show();
113 | }
114 | };
115 |
116 | //----------------------------------------
117 | /**
118 | * @see android.view.View.OnClickListener#onClick(android.view.View)
119 | */
120 | //----------------------------------------
121 | @Override
122 | public void onClick(View v)
123 | {
124 | //initialize server socket in a new separate thread
125 | new Thread(initializeConnection).start();
126 | String msg = "Attempting to connect…";
127 | Toast.makeText(USBServerActivity.this, msg, msg.length()).show();
128 | }
129 |
130 | @Override
131 | public void onDestroy()
132 | {
133 | super.onDestroy();
134 | try
135 | {
136 | // Close the opened resources on activity destroy
137 | USBServerActivity.nis.close();
138 | out.close();
139 | if (server != null)
140 | {
141 | server.close();
142 | }
143 | }
144 | catch (IOException ec)
145 | {
146 | Log.e(USBServerActivity.TAG, "Cannot close server socket" + ec);
147 | }
148 | }
149 | }
--------------------------------------------------------------------------------