从另一个应用程序访问一个应用程序的数据库 [英] Accessing the database of one application from another application

查看:132
本文介绍了从另一个应用程序访问一个应用程序的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个应用程序,现在我想使用新的备份应用程序复制该正在运行的应用程序的数据库.我通过使用以下值进行DB_PATH + DB_NAME来创建数据库路径:

I've built an application and now I want to copy the database of that running application using my new backup application. I create my database path by doing DB_PATH + DB_NAME, using the following values:

DB_PATH = "/data/data/iCam.Cam/";
DB_NAME = "testdb.db";

我有将数据库从给定路径复制到SD卡的代码.但是,当我最初使用以下方法检查数据库时,它返回false:

I have code which copies the database from the given path to the SD Card. However, when I initially check the database using the following method, it returns false:

public boolean checkDataBase() {    
    SQLiteDatabase checkDB = null;

    try {
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) {
        e.fillInStackTrace();
        // database does't exist yet.
    }

    if (checkDB != null) {
        checkDB.close();
    }

    return checkDB != null ? true : false;
}

关于如何实现这一目标的任何建议?

Any suggestions on how to achieve this?

推荐答案

仅当在自定义内容提供程序中创建正在运行的应用程序数据库时,才能使用同一数据库.

You can use the same database only if you created the running application database in custom content provider.

您不能从正在运行的应用程序直接访问数据库.

You cannot directly access the database from running application.

但是,如果您在定制内容提供程序"中创建正在运行的应用程序数据库,则可以在权限的帮助下直接访问该数据库.

But if you create your running application database in Custom Content Provider then with the help of authorities you can directly access the database.

在这种情况下,您甚至不需要复制该数据库.

In this case you don't even need to copy that database.

请参阅此链接以进行自定义内容提供商.

Refer this link for custom content provider.

这篇关于从另一个应用程序访问一个应用程序的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆