开发者

android: transfer sqlite database from pc to device via usb programatically

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 h开发者_开发知识库andheld 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


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);
    }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜