如何在运行时在Android应用程序中查看sqlite数据库 [英] How to view sqlite database in android application at run time

查看:99
本文介绍了如何在运行时在Android应用程序中查看sqlite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 DDBMS角度复制数据->文件浏览器->数据-> [my_app_package] 然后 PULL ,这在我在模拟器上运行应用程序时有效,但在移动设备上运行应用程序时,数据文件夹下未显示任何内容。

I am trying to copy data from DDBMS perspective -> file explorer -> data -> [my_app_package] then PULL this is working when I am running application on emulator but when I am running application on mobile nothing is shown under data folder.

我也曾尝试从adb做同样的事情,但是它不起作用。.是他们探索我的应用程序创建的sqllite数据库而不用扎根我的手机的任何方法。

I have also tried to do same thing from adb but its not working.. Is their any way to explore sqllite database created by my application without rooting my phone.

推荐答案

一个人肯定可以通过编程从Android设备检索数据库 .db 文件。我曾经在名为 Developer Options 的应用程序下放置了另一个设置,该设置将 .db 文件复制到 sdCard

One can surely retreive database .db file from Android Device programmatically. I used to put one more setting under my application named Developer Options which copy .db file into sdCard.

以下代码将 .db 复制到 sdcard 。使用 backupDBPath currentDBPath(将名称复制为 .db )更改为类似的名称。您给了数据库名称)

Following code copy .db to sdcard. Change your copied .db file name into whatever like to with backupDBPath and currentDBPath (Name which you gave to your database name).

public void dev()
    {
        try {
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();

            if (sd.canWrite()) {
                String currentDBPath = "/data/data/" + getPackageName() + "/databases/ZnameDB";
                String backupDBPath = "ZnameDB_Dev.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();
                    Toast.makeText(SettingsActivity.this, "Database Transfered!", Toast.LENGTH_SHORT).show();
                }
            }
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }
  }

PlayStore ,可用来查看 .db 文件。我使用 aSQLiteManager android应用程序来查看 .db 文件。

There are many application available in PlayStore with which you can view your .db file. I used aSQLiteManager android application to view .db file.

这篇关于如何在运行时在Android应用程序中查看sqlite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆