我正在开发一个应用程序,我知道我的数据库*.db将出现在data/data/com.****.***

我可以在sqlite管理器的帮助下从Eclipse中的AVD访问这个文件

但是我的安卓手机无法访问这个文件。 我谷歌了一下,它说我需要在我的手机上查找,但我不想这样做。

我如何访问我的data/data/.....目录在我的安卓手机“没有根它”?

是否可以更改目录data/data.....的用户权限没有生根?


要做到以上任何一项(即从手机本身访问受保护的文件夹),你仍然需要root。(这包括更改/data文件夹的挂载权限并访问它)

如果没有root,除了通过代码从应用程序内部读取外,直接访问/数据是不可能的。所以你可以试着把那个文件复制到sdcard或者其他可以访问的地方,然后,你就可以正常访问它了。

如果您使用的是开发人员设备,那么root不会使您的保修失效。对不起,我没有别的办法了。

使用eclipse中的文件资源管理器。Select Windows => Show View => Other…>文件资源管理器。

另一种方法是通过adb提取文件:

adb pull /system/data/data/<yourpackagename>/databases/<databasename> /sdcard

其中一个简单的方法是在sd卡上创建数据库。因为你无法访问手机内存中的数据文件夹,除非你对手机进行root操作。那么为什么不简单地在sd卡上创建数据库呢?

此外,如果您愿意,可以编写一些文件复制代码,将现有的数据库文件(从内部内存)复制到外部内存,而不需要任何根。

你也可以尝试使用根资源管理器应用程序获取db。如果这不起作用,那么你可以试试这个:

打开cmd 改变目录,进入“平台工具” 类型为“adb shell” 苏 在设备上按“允许” chmod 777 /数据/数据/数据/数据/数据/ com.application。包/数据/数据/ com.application.package / * 在Eclipse中打开DDMS视图,然后从那里打开“FileExplorer”以获得所需的文件

在此之后,您应该能够浏览根设备上的文件。

你可以复制这个db文件到eclipse资源管理器的某个地方(例如:sdcard或PC),你可以使用sqlite访问和更新这个db文件。

直接在手机上访问这些文件很困难,但你可以将它们复制到你的电脑上,在那里你可以做任何你想做的事情。 没有根你有两个选择:

If the application is debuggable you can use the run-as command in adb shell adb shell run-as com.your.packagename cp /data/data/com.your.packagename/ Alternatively you can use Android's backup function. adb backup -noapk com.your.packagename You will now be prompted to 'unlock your device and confirm the backup operation'. It's best NOT to provide a password, otherwise it becomes more difficult to read the data. Just click on 'backup my data'. The resulting 'backup.ab' file on your computer contains all application data in android backup format. Basically it's a compressed tar file. This page explains how you can use OpenSSL's zlib command to uncompress it. You can use the adb restore backup.db command to restore the backup.

可能要访问这个文件夹需要管理员权限。

所以你有两个选择:-

根您的设备,然后尝试访问此文件夹 使用模拟器

附注:如果您正在使用上述两个选项中的任何一个,您可以通过以下步骤访问此文件夹

打开DDMS透视图->您的设备->(选择文件资源管理器从 右窗口选项)选择package -> data -> data -> package name - >文件

从那里你可以调出你的文件

打开命令提示符 将目录改为E:\Android\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\sdk\platform-tools 输入以下命令 Adb -d shell 执行命令-as com.your.packagename cat databases/database.db > /sdcard/database.db 将目录更改为cd /sdcard,确保database.db在那里。 Adb pull /sdcard/database.db或者简单地从设备复制database.db。

在未根的Android 5.0+设备上从可调试应用程序文件夹(例如/data/data/package.name/databases/file)中提取文件最简单的方法(只是一个简单的步骤)是使用以下命令:

adb exec-out run-as package.name cat databases/file > file

我也曾经遇到过同样的问题。除了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

在根设备上,正确的解决方案是:

Open cmd
Change your directory and go into 'Platform tools'
Type 'adb shell'
su
Press 'Allow' on device
chmod 777 /data /data/data /data/data/*
Open DDMS view in Eclipse/IntelliJ and from there open 'FileExplorer' to get your desired file

原来的解决方案是可行的,但是chmod将返回未知的目录。将chmod命令更改为/data/data/*可以从Intellij中的DDMS访问data目录中的所有子文件夹。我假设同样的解决方案也适用于Eclipse DDMS。

更新 我的发现很奇怪。我正在IntelliJ (Android设备监视器)中使用DDMS运行Nexus 6。我已经构建了一个小入门应用程序。该应用程序将数据保存到data/data/com.example.myapp/files中的.csv文件

When I first started to try to access this file on my Nexus 6, I found that I have to root the device.. I could see the data folder, but trying to open it would not work. As mentioned online in other places, the expand + would vanish then reappear shortly thereafter (note, there are solutions on the web that claim to allow access to these folders without rooting, I didn't find them till too late, and I'm not sure if I prefer not to root anyway ((I'd rather be able to do it manually than rely on an app or command prompt to give me my solutions))). I rooted my 6 and tried DDMS again.

在这一点上,它显示了数据文件夹,我可以展开文件夹,看到com。目录,但我无法打开任何一个。就在那时,我发现了上面的解决方案。最初的说明对这部分不起作用:

chmod 777 /data /data/data /data/data/com.application.pacakage /data/data/com.application.pacakage/*

就在那时,我尝试了我发布的解决方案:

chmod 777 /data /data/data /data/data/*

这个解决方案似乎是可行的,但只适用于某些文件夹。我现在可以展开myapp文件夹,但不能展开其中的文件目录。

在这一点上,我尝试了一段时间,然后想到为什么不直接在我需要的目录上尝试它,而不是尝试这些通配符条目。

chmod 777 /data /data/data /data/data/com.example.myapp/*

紧随其后的是:

chmod 777 /data /data/data /data/data/com.example.myapp/files

这些命令允许我展开并查看应用程序目录中的文件,以确认.csv文件被正确保存。

希望这能帮助到一些人。我为此挣扎了好几个小时!

(更奇怪的是,权限并没有传递给文件目录的.csv文件。我的文件目录权限读DRWXRWXRWX和我的log.csv文件权限读-rw-rw---- ..仅供参考)

从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

如果你使用的是Android Studio 3.0或更高版本,请遵循以下步骤。

单击“查看>工具Windows >设备文件资源管理器”。 展开/data/data/[package-name]节点。

只能展开在非根设备上以调试模式运行的包。

您还可以尝试将文件复制到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 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 "

你可以像这样下载一个文件:

Adb执行run-as debug .app.package.name cat files/file.mp4 > file.mp4

在你下载之前,你可能不想看看你的App-Directory中的文件结构。要做到这一点,请按照上面THelper提到的步骤:

adb shell
run-as com.your.packagename 
cd files
ls -als .

Shahidul提到的Android-Studio方式(https://stackoverflow.com/a/44089388/1256697)也可以。对于那些在菜单中没有看到DeviceFile资源管理器选项的人:请确保在Android Studio中打开/ Android - directory。 例如,react-native用户在他们的Project-Folder中有这个和/ios-Directory在同一级别。

SQLlite数据库存储在用户的手机,它隐藏在路径下:

/Data/Data/com.companyname.AppName/File/

你有两个选择:

你可以根你的手机,这样你就可以查看你的隐藏 db4文件 这不是解决方案,而是一种变通办法。为什么不直接创建测试呢 使用“select”语句在其中显示数据库表的页面。

简单的答案是否定的。在即将到来的Android 13上,你不能访问任何东西 /存储/模拟/ 0 / Android / * 目录没有根你的设备或连接到PC,当然不是在Pixel设备。

阅读Android源页面,使用ADB访问这样的应用程序数据: https://developer.android.com/training/data-storage/manage-all-files