【发布时间】:2014-06-16 07:17:51
【问题描述】:
在我的应用程序中,我尝试通过以下代码打开现有的 android 数据库以修改其内容:
String DB_PATH = "/data/data/com.sec.android.provider.logsprovider/databases/";
String DB_NAME = "logs.db";
..........................
SQLiteDatabase mSqLiteDatabase = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, SQLiteDatabase.OPEN_READWRITE);
数据库路径正确,我还更改了数据库文件的权限。但是总是报错“Fail to open database file (code 14):, while compile: PRAGMA journal_mode”
我的清单.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.logsfiller"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.logsfiller.LogFillerActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我做错了吗?请帮忙! 谢谢!
【问题讨论】:
-
检查您的应用程序的权限(您需要 WRITE_EXTERNAL_STORAGE)并尝试使用另一种方法:stackoverflow.com/a/6781029/1001401 我认为 - 您可以使用上下文方法:Context.openOrCreateDatabase:developer.android.com/intl/ru/reference/android/content/…
-
我已经做了,但同样的问题:|
-
在打开之前创建数据库吗?还是您创建目录“/databases/”?
-
你能发布你的 manifest.xml 吗?
-
@nfirex 这个数据库属于其他应用程序,现在我想访问和修改它。
标签: android database-connection android-sqlite android-contentprovider