android:通过USB以编程方式将sqlite数据库从PC传输到设备

发布于 2024-09-25 03:59:18 字数 365 浏览 9 评论 0原文

情况是这样的。我有一个用 vb.net 编写的应用程序。它由一个或两个部分组成。一个在 PC 上,另一个在手持式 Windows Mobile 6 设备上。桌面程序通过 USB 使用 activesync 将 SQLServer 紧凑型数据库与手持设备进行传输。我们可能希望考虑让 Android 手持设备也受此应用程序支持。现在我知道我可以将 SQLite 与 .net 一起使用。我知道我可以使用 ADB 将数据(以及数据库文件)推送到设备或从设备中提取数据。

我需要知道的是我是否可以直接从 VB.NET 作为 API 或 SDK 访问 ADB,而不必手动执行。

当然,除非我遗漏了一些东西,并且我可以通过其他方式将数据库复制到设备或从设备复制数据库?

感谢期待

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心奴独伤 2024-10-02 03:59:18

没有直接的 API 可以实现这一点。我们有一个类似的场景,用户从桌面客户端(在我们的例子中基于 Java Swing)同步内容(即数据库),该客户端手动使用 adb,到目前为止工作正常。

在我们的 java 客户端中,我们会调用:

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

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);
    }
}
余厌 2024-10-02 03:59:18

我认为 VB.Net 应用程序将数据库移动到手机的更简单方法是将 sqlite 文件写入或复制到安装的手机卷上的(可配置)目录(例如手机的 SD 卡) -卡片)。

然后,Android 应用程序可以使用诸如 SQLiteDatabase.openDatabase< 之类的方法/code>使用相同的路径打开并使用传输的数据库。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文