Android 我可以指定sqlite数据库的路径吗
我在android中创建了sqlite数据库,如下代码所示,并向其中添加了一些记录。然后我想复制那个数据库,以便在数据库中使用它 在应用程序中,我的数据库名为GEOLOC.db,我搜索了它,但没有找到,尽管它包含数据 请让我知道Android 我可以指定sqlite数据库的路径吗,android,sqlite,Android,Sqlite,我在android中创建了sqlite数据库,如下代码所示,并向其中添加了一些记录。然后我想复制那个数据库,以便在数据库中使用它 在应用程序中,我的数据库名为GEOLOC.db,我搜索了它,但没有找到,尽管它包含数据 请让我知道 1-如何知道sqlite数据库的保存位置 2-我可以指定保存数据库的路径吗 代码: 通常,特定的sqlite数据库特定于单个应用程序。但是,除非手机已根目录,否则您将无法查看它。事实上,它通常位于以下路径: //data/data/<Your-Applicatio
1-如何知道sqlite数据库的保存位置 2-我可以指定保存数据库的路径吗 代码:
通常,特定的sqlite数据库特定于单个应用程序。但是,除非手机已根目录,否则您将无法查看它。事实上,它通常位于以下路径:
//data/data/<Your-Application-Package-Name>/databases/<your-database-name>
数据库名称存储在通过以下声明扩展SqliteOpenHelper的类中:
private static final String DATABASE_NAME = "buspass";
为了在应用程序之间共享数据,如果它们都是由您开发的,您需要在两个应用程序的清单文件中指定共享用户id
在两个应用程序中使用相同的DBAdapter。在托管数据库的应用程序中,使用本机上下文调用DBAdapter
DBadapter hostDBAdapter = new DbAdapter(getApplicationContext());
performerDBadapter.open();
In the second app, access the database with the context of the database hosting app.
First, define the shared context:
Context sharedContext = null;
try {
sharedContext = this.createPackageContext("replace.with.host.package.name", Context.CONTEXT_INCLUDE_CODE);
if (sharedContext == null) {
return;
}
} catch (Exception e) {
String error = e.getMessage();
return;
}
然后使用共享上下文打开DBAdapter:
DbAdapter sharedDBadapter = new PerformerDbAdapter(sharedContext);
sharedDBadapter.open();
清单文件应具有以下代码:
PACKAGE_NAME = getApplicationContext().getPackageName();
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:sharedUserId="my.app" ... >
希望这能有所帮助:在一些方便的上下文中,可能重复了如何知道sqlite数据库保存在哪里。我可以指定保存数据库的路径吗?-我认为这与API级别8或9一样有效,尽管通常不需要更改路径。
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:sharedUserId="my.app" ... >