views:

153

answers:

2

The situation is this. I have an application written in vb.net. it consists or two parts. One on a PC and the other on a handheld windows mobile 6 device . The desktop program transfers a SQLServer compact database to and from the handheld device using activesync via USB. Potentially we want to look into having android handheld devices also supported by this application. Now I know I can use SQLite with .net. I know I can use ADB to push and pull data (and therefore the database files) to and from the device.

What I need to know is can I access ADB directly from VB.NET as an API or SDK rather than having to do it manually.

Unless of course I'm missing something and I can copy databases to and from the device in some other way?

thanks in anticipation

A: 

I think the easier way for your VB.Net application to move the database to the phone is to write or copy the sqlite-file to a (configurable) directory on a mounted phone volume (e.g. the phone's sd-card).

The Android application can then use methods like SQLiteDatabase.openDatabase with the same path to open and work with the transferred database.

Josef
Hi Josef and thanks for the answer. I have thought of that approach. I need it to mimic the process of the windows version where you simply say in the desktop program that you want to download data or upload all the data from the android device. I want to avoid putting the android device in a specific mode and have to locate the drive letter it sets up on connection to the PC. Simply plug it in and transfer data without the guy doing it needing to do any other setup is what I'm aiming for. So it's pretty much plug and play. I dont know if this is possible but I need to get as close as I can.
Dream Architect
+1  A: 

There's no direct API for that. We have a similar scenario, where the user syncs content (i.e. also the database) from a desktop client (in our case Java Swing based), which utilized adb manually and it's working fine so far.

In our java client, we'd call:

private static final String ADB_PUSH = "\"" + Utility.getWorkDir() + File.separator + "adb\" -s %s push \"%s\" %s";


/**
 * Pushes a file to a connected device via ADB
 * @param deviceId Device serial number
 * @param from Path of source file (on PC)
 * @param to Path of file destination (on device)
 */
public static void push(String deviceId, String from, String to) {
    try {
        String cmd = String.format(ADB_PUSH, deviceId, from, to);
        System.out.println("adb push: " + cmd);
        Process p = Runtime.getRuntime().exec(cmd);
        InputStream is = p.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);

        String line;
        while ((line = br.readLine()) != null) {
            System.out.println("adb: " + line);
        }
    } catch (IOException e) {
        System.out.println(e);
    }
}
Mathias Lin
Hi Mathias, that sounds perfect. All I have to do now is decifer the Java code as the only Java I have done up until now is the little android I've been teaching myself. This is good news though and once I've understood your code I will see if I can make it work with .net
Dream Architect