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.
Related
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)
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.
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
I do not know how to start building upon this simple idea :
When an android phone is connected to a PC, a Java application running on the PC detects the device and starts synchronizing the contacts in the android phone.
Can anyone help me how do I start this ? I know how to write applications in Java but have never worked with android OS or have made application for the android operating system. That is the reason I am unable to start this.Please tell,if there is anything I need to delve in before I should start.
The contacts info can only be got in the android apps, so you have to write an android app and a pc app, and transfer data between them.
When a device is connected to pc, start your pc app automatically.
Install your android app to the device.
adb install apk-path
Start the android app.
adb shell am start -n pkgname/activityname
Start a tcp connecton.
adb forward tcp:port tcp:port
read this page for details.
Try to collect contacts in android app and transfer them to pc. There are many articles about how to get contacts in android, and the data transmission will use Serialization and Socket programming.
adb (android debug tool) is a android sdk tool, you need to learn more about it.
I'm now writing a project on android and my program must able to transfer / replace a file to my computer with certain address to sync my app with my app on my computer and reverse (from PC to device) only by pressing a single button in my program.
Use http://developer.android.com/tools/help/adb.html#forwardports to forward a TCP/IP connection over the USB cable. Your app on the phone can act as a TCP server and receive arbitrary commands.
The downside of this solution is that you have to bundle the adb executable with your program and the user must have the proper drivers installed (that means mass-storage connection is not enough). The sources for adb are available, if you want.