Android reverse tethering over usb (not root) - java

I'm developing an enterprise app in PhoneGap, and I want to work offline with some data, and through a plugin (with code written in Java) send the processed data back over the LAN Network (when this were detected), but I need some code samples to create a reverse tethering without rooting the device nor using external apps.
I'm trying to avoid creating a local component in the windows machine, I want to send the data directly using REST commands.
Any code samples or suggestions are welcome.

Have you tried this simple solution
For Windows: Install USB drivers from Android SDK
Connect USB cable and activate USB Tethering. You should see on linux or windows a new network interface.
On windows, Bridge the 2 network interfaces
Setup usb0 interface of your phone. You have two options:
From your computer, execute:
./adb shell netcfg usb0 dhcp
Or in a terminal on your phone, type:
su
netcfg usb0 dhcp
You should now be able to connect to Internet on your phone using your computer’s Internet connection.
http://acetips.wordpress.com/2011/10/07/reverse-usb-tethering/ and
http://blog.mycila.com/2010/06/reverse-usb-tethering-with-android-22.html
for run adb command from your android application you could use
String exeeCmd = "netcfg usb0 dhcp";
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(exeeCmd);
} catch (IOException e) {
e.printStackTrace();
}
apply required permitions

I know this comes quite late, but it seems no real solution has been found yet, and this might help fellow readers:
As I could not find any solution myself, I have developed an app that offers Reverse Tethering for unrooted Android devices running Android 4.0 or higher. All major desktop operating systems are supported.
The app is available on Google Play: https://play.google.com/store/apps/details?id=com.floriandraschbacher.reversetethering.free

Maybe you could integrate reverse tethering tools tools into your app

Related

Run android emulator or sandbox on mobile itself

Is there any tool out which runs an apk on a real mobile device, like an emulator. The tool would need to execute the apk properly, but also be able to intercept certain commands. Any chance?
To make it more clear, I dont need a shell command to start and stop or so. I need more of a container emulator like tool, which might be able to inject/alter running compiled code.
The ADB connects to running devices, those are:
Running emulators;
Devices connected trough USB that have "Developer options on"+"USB debugging" on device enabled
Also, you need to accept in the device the key for debugging trough ADB after connecting.
Obs: Drivers may be necessary for the device, (google has a package in SDK manager with Google Drivers that works for some devices too)

Cordova Android Development: Looking for OTG cable options for debugging with peripherals connected

I'm developing a Cordova Plugin for Android that interacts with a printer connected to my Android device's USB port. I also have Ionic in the mix running a working Anular application. I have the Plugin working, but getting to that point was painful. There were many iterations of deploying the app from my laptop (using ionic run Android) swapping the otg cable out and pluging in the printer and testing.
I'm looking for a better develop/debug story. I'm planning to add additional features to the Cordova plugin and would like to find a cable configuration that lets me keep the Android device connected to my laptop while the printer is also connected the Android device.
I've tried a few different after market cables, but everything seem to only support charging the device while connected to the peripheral devices. Nothing seems to allow me to stay connected to the laptop and have a peripheral connected simultaneously.
Is anyone aware of a USB Hub, Switch or Router that could help ease my pain, or have suggestions on how I can easily debug my Java based plugin while it is connected to the USB printer. At a minimum I'd like to be able to attach a debugger to my plugin and step through the Java code.
Using an Emulator is out of the question because the performance is simply unbearable.
Sorry in advance if this question is not appropriate here.
I think I have a better solution for you, you can deploy to your device using adb over Wi-fi and keep your printer cable connected to test your app, here is how:
Connect your android device to your computer using a USB cable
From a command line run adb tcpip 1234 // or any port of your chosing
disconnect your android USB cable
run adb connect <your-phone-ip>:1234
Connect your printer using the USB cable
run ionic run android to deploy your app.
I just tested this combo with a Mac and an Android Nexus 5 and it works like a charm.

Can an iOS application communicate with a Java application on my Mac via bluetooth without creating an OS X application?

I have an iOS application with a tableview which I would like to send text strings via bluetooth to my Macbook indicating which cell was selected by the user. Both have bluetooth 4.0. This information will be fed into a Java application. From a CoreBluetooth perspective, the iOS device will be a peripheral and my Mac would be the central.
The problem I'm having is around setting up the central. Apple documentation gives a lot detail around building a central manager within a Mac OS X application (xcode, CBCentralManager). However, I'd like the data to be pulled into a Java application running on my Mac.
Do I need to build a Mac OS X application to wrap my Java application to build this type of communication? Should I consider another method of bluetooth communication i.e. BluetoothManager.Framework? I do not need to submit this to the Apple Store. Is this a TCP/IP problem?
I figured it out. My solution is based on Ray Wenderlich's Network Tutorial for iOS. I created the python server, tethered my iOS device via bluetooth to my Mac, and transmitted messages via port 80 on my Bluetooth PAN IP address. Then I created a Java client to connect to the python server to receive the messages!

Can I use JSSC to communicate with usb devices

I need to communicate with a device with a rs232 out put,but my laptop doesn't
have a rs232 port,then i bought a rs232 to USB converter and now i want to listen on the
usb port for data,can i use jssc to achive this. ???
I know this is months old, but I see no answers. The answer is yes.
You can test your cable by going to the JSSC google code project page and access the Wiki tab's JSSCTerminal link. It's a Java Applet Terminal program that allows you to connect a device via your cable, set port, speed, stop bits, etc., and then send commands and receive data.
I am successfully using JSSC to write Java programs to download data from Blood Glucose Meters and GPS trackers to my Linux and Windows 7 desktops and my Windows 7 laptop. My serial-to-USB cable uses an older Prolific chipset. The FTDI chipset should work too.
Once the appropriate drivers are loaded in your OS the OS sees the connected cable as a COM port in Windows and usually as the serial device /dev/ttyUSB0 in Linux/Mac. At this point you can use any Terminal/Comm program or library to interact with them including JSSC. You can download and run the examples unchanged from the JSSC project.
this lib is used by arduino ide on that purpose https://github.com/arduino/Arduino/blob/master/arduino-core/src/processing/app/Serial.java

Desktop application to connect to an android device

I have to create a desktop application to syncronize apps between the PC and the Android device (a tablet in this case)
The sync will be quite basic, I need to copy a few files. But also, if the tablet doesn't have my app, the desktop app should be able to install the apk to the tablet.
I have searched all over and the only pointer I found is mention to a ddmlib (an AndroidDebugBridge library) that I can use, but I haven't found where to find it or how to use it.
So the question how I can work with ddmlib? or if there are other options to sync my Desktop app with my Android app?
Thanks in advance for your time
If I was writing your sync software, I would use adb commands to install the application on the phone, then use adb forward to create tcp/ip connection to the phone and use that connection to transmit whatever data your application would like to send back and forth, probably even encrypting the traffic.
I would advise against using adb for data transfers, because it would not read or write your application private files, where all the secrets are kept, and sending the data to the world-readable /sdcard is bad for two reasons:
it's world-readable and -writeable, your data will be exposed to everyone
some devices just don't have /sdcard or have it unmounted or unavailable for other reasons
ps. For bonus points, you may try not to use adb commands, but access the adb server directly (it usually listens on the local TCP port 5037).
With the android debug bridge you need to run:
adb push <local> <remote>
to copy to the device,
adb pull <remote> [<local>]
to copy from device or
adb install [-l] [-r] [-s] <file>
to install an apk on the device.

Categories