我正在开发一个应用程序,我知道我的数据库*.db将出现在data/data/com.****.***
我可以在sqlite管理器的帮助下从Eclipse中的AVD访问这个文件
但是我的安卓手机无法访问这个文件。 我谷歌了一下,它说我需要在我的手机上查找,但我不想这样做。
我如何访问我的data/data/.....目录在我的安卓手机“没有根它”?
是否可以更改目录data/data.....的用户权限没有生根?
我正在开发一个应用程序,我知道我的数据库*.db将出现在data/data/com.****.***
我可以在sqlite管理器的帮助下从Eclipse中的AVD访问这个文件
但是我的安卓手机无法访问这个文件。 我谷歌了一下,它说我需要在我的手机上查找,但我不想这样做。
我如何访问我的data/data/.....目录在我的安卓手机“没有根它”?
是否可以更改目录data/data.....的用户权限没有生根?
当前回答
从Android备份到Desktop
打开命令行cmd并运行以下命令: adb backup -f C:\Intel\xxx。Ab -noapk你的。app.package。 不输入密码,点击备份我的数据。 确保不要保存在C根盘上。你可能会被拒绝。 这就是为什么我保存C:\英特尔。
来提取*。ab文件
点击这里下载:https://sourceforge.net/projects/adbextractor/ 解压缩下载的文件,并导航到解压缩的文件夹。 使用自己的文件名运行:java -jar abe.jar unpack c:\Intel\xxx英特尔ab c: \ \ xxx.tar
其他回答
您还可以尝试将文件复制到SD卡文件夹,这是一个公共文件夹,然后您可以将文件复制到您的PC上,在那里您可以使用sqlite访问它。
下面是一些你可以用来将文件从data/data复制到公共存储文件夹的代码:
private void copyFile(final Context context) {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath =
context.getDatabasePath(DATABASE_NAME).getAbsolutePath();
String backupDBPath = "data.db";
File currentDB = new File(currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
清单:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
我也曾经遇到过同样的问题。除了adb shell或根设备,没有办法在android设备中直接访问文件。
下面是02种替代方案:
1)
public void exportDatabse(String databaseName)
{
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//"+getPackageName()+"//databases//"+databaseName+"";
String backupDBPath = "backupname.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
}
}
2)试试这个:https://github.com/sanathp/DatabaseManager_For_Android
其中一个简单的方法是在sd卡上创建数据库。因为你无法访问手机内存中的数据文件夹,除非你对手机进行root操作。那么为什么不简单地在sd卡上创建数据库呢?
此外,如果您愿意,可以编写一些文件复制代码,将现有的数据库文件(从内部内存)复制到外部内存,而不需要任何根。
使用eclipse中的文件资源管理器。Select Windows => Show View => Other…>文件资源管理器。
另一种方法是通过adb提取文件:
adb pull /system/data/data/<yourpackagename>/databases/<databasename> /sdcard
adb backup didn't work for me, so here's what I did (Xiaomi Redmi Note 4X, Android 6.0): 1. Go to Settings > Additional Settings > Backup & reset > Local backups. 2. Tap 'Back up' on the bottom of the screen. 3. Uncheck 'System' and 'Apps' checkmarks. 4. Tap detail disclosure button on the right of the 'Apps' cell to navigate to app selection screen. 5. Select the desired app and tap OK. 6. After the backup was completed, the actual file need to be located somehow. Mine could be found at /MIUI/backup/AllBackup/_FOLDER_NAMED_AFTER_BACKUP_CREATION_DATE_. 7. Then I followed the steps from this answer by RonTLV to actually convert the backup file (.bak in my case) to tar (duplicating from the original answer): " a) Go here and download: https://sourceforge.net/projects/adbextractor/ b) Extract the downloaded file and navigate to folder where you extracted. c) run this with your own file names: java -jar abe.jar unpack c:\Intel\xxx.ab c:\Intel\xxx.tar "