DDMS 文件资源管理器无法访问数据\数据 (HTC Desire HD)

发布于 2024-10-16 10:24:08 字数 166 浏览 6 评论 0原文

我正在编写一些 SQLite 代码,并且想检查数据库。如果我在模拟器上运行代码,我可以使用 DDMS 文件管理器从 data\data\myProject\databases 中提取文件,但如果我在实际硬件上运行它,则无法访问 data\data 文件夹。除了获取手机root权限之外,还有什么办法可以解决这个问题吗?

I'm working on some SQLite code and would like to examine the database. If I run the code on the emulator I am able to pull the file from data\data\myProject\databases using the DDMS file manager but if I run it on actual hardware the data\data folder is inaccessible. Is there any way around this other than gaining root access to the phone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

鹤舞 2024-10-23 10:24:08

SQLite 数据库实际上只是存储在手机内存中的一个文件,您可以将其复制到手机 SD 卡,然后从 PC 轻松访问它。下面的函数完全可以满足您的需要。只需确保在使用函数之前更改包名称和数据库名称即可。

public static void backupDatabase() throws IOException {
    //Open your local db as the input stream
    String inFileName = "/data/data/your.package.name/databases/database.sqlite";
    File dbFile = new File(inFileName);
    FileInputStream fis = new FileInputStream(dbFile);

    String outFileName = Environment.getExternalStorageDirectory()
                                                    + "/database.sqlite";
    //Open the empty db as the output stream
    OutputStream output = new FileOutputStream(outFileName);
    //transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = fis.read(buffer))>0){
        output.write(buffer, 0, length);
    }
    //Close the streams
    output.flush();
    output.close();
    fis.close();
}

正如您可以从代码中观察到的,数据库始终存储在以下文件夹中:

/data/data/your.package.name/databases/

名称(在我们的示例中为“database.sqlite”)是您在扩展 SQLiteOpenHelper 时选择的名称。显然,您还需要将“your.package.name”替换为您的应用程序包的名称。

SQLIte Database is actually just a file stored in phone memory, which you can copy to your phone SD card and then easily access it from your PC. Below is the function which does exactly what you need. Just make sure to change your package name and database name before using function.

public static void backupDatabase() throws IOException {
    //Open your local db as the input stream
    String inFileName = "/data/data/your.package.name/databases/database.sqlite";
    File dbFile = new File(inFileName);
    FileInputStream fis = new FileInputStream(dbFile);

    String outFileName = Environment.getExternalStorageDirectory()
                                                    + "/database.sqlite";
    //Open the empty db as the output stream
    OutputStream output = new FileOutputStream(outFileName);
    //transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = fis.read(buffer))>0){
        output.write(buffer, 0, length);
    }
    //Close the streams
    output.flush();
    output.close();
    fis.close();
}

As you may observe from the code, database is always stored in the folder:

/data/data/your.package.name/databases/

Name (in our example "database.sqlite") is the one you picked when extending SQLiteOpenHelper. Obviously, you also need to replace "your.package.name" with the name of your application package.

鹿童谣 2024-10-23 10:24:08

你必须root你的设备。转到命令提示符并转到 adb 所在的位置。

例如

C:\Program Files\Android\android-sdk\platform-tools

类型 adb root。现在转到文件资源管理器并检查。

You have to root your device. Go to command prompt and go to the location where your adb is located.

e.g.

C:\Program Files\Android\android-sdk\platform-tools

type adb root. now go to your file explorer and check.

愚人国度 2024-10-23 10:24:08

使用 adb 将文件复制到 /mnt/sdcard

cp /data/data/<packagename>/databases/<dbname>/<filename> /mnt/sdcard 

,然后从 /mnt/sdcard 使用复制到桌面

adb pull /mnt/sdcard/<filename> 

,然后使用 sqlite3 来查看它。

Copy file to /mnt/sdcard using

cp /data/data/<packagename>/databases/<dbname>/<filename> /mnt/sdcard 

using adb and then copy to your desktop from /mnt/sdcard using

adb pull /mnt/sdcard/<filename> 

and then use sqlite3 to view it.

北凤男飞 2024-10-23 10:24:08

我相信您的应用程序可以更改其本地存储数据文件的unix权限,以便其他应用程序和adb可以访问它们。

但是,您的应用程序无法更改安全电话的 /data 目录上缺乏列表权限的情况。

因此,您必须使用“adb pull /full/path/to/file”来获取文件 - 您无法浏览到该文件,因为您无法生成 /data 或文件的其他几个中间目录父级的列表。

I believe that your application can change the unix permissions of its local storage data files such that they become accessible to other applications and to adb.

However, your application cannot change the lack of list permission on the /data directory of a secured phone.

As a result, you would have to grab the file with 'adb pull /full/path/to/file' - you cannot browse to it since you cannot generate a listing of /data or likely several other intermediate directory parents of your file.

嘴硬脾气大 2024-10-23 10:24:08

实际上,解决这个问题的唯一方法就是将文件放在您可以访问它的地方,例如在开发过程中放在 SD 卡上。然后,一旦您对一切正常工作感到满意,就可以将文件放在您想要的位置。

我这么说是因为我有零售版 Nexus One 和开发版 Nexus One。在使用 DDMS 文件资源管理器时,我注意到我可以浏览开发人员设备上的数据文件夹,但无法在零售设备上浏览。我root了我的零售设备,但没有帮助。

所以我想必须对这个问题进行更多研究。但在那之前我希望这会有所帮助。

Really about the only way around this is to put your file some place where you CAN get access to it like out on the sdcard during development. Then once you are satisfied things are work correctly put the file where ever you want.

I say this because I have a retail Nexus One and developer Nexus One. While using DDMS File Explorer I noticed I could browse the data folder on the developer device but could not on the retail device. I rooted my retail device and it did not help.

So I guess more research has to be done on this problem. But until then I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文