自应用发布以来,我一直在使用Android Studio开发应用。

直到最近,一切都很好,我必须调试和检查数据库文件。由于我不知道如何直接看到数据库,当我调试生成数据库文件时,我不得不将数据库文件从我的手机导出到PC上。

为此,我必须打开DDMS >文件资源管理器。一旦我打开DDMS,我必须重新连接USB,我失去了调试线程。在检查数据库文件之后,我必须关闭DDMS并重新连接USB以回到调试模式。

这太复杂了。有人有更好的方法来做到这一点在Android Studio(我知道它更容易在Eclipse) ?


当前回答

最后,Android Studio通过数据库检查器选项卡支持此功能。您可以轻松应用视图/更新/查询操作。它现在还不是稳定的渠道,但你可以尝试Android Studio 4.1 Canary 5或更高版本。

您可以在这里看到数据库检查器的样子

你可以在这里下载相应的版本

其他回答

从Android Studio查看数据库:

选项1:

Download and install SQLiteBrowser. Copy the database from the device to your PC: Android Studio versions < 3.0: Open DDMS via Tools > Android > Android Device Monitor Click on your device on the left. You should see your application: Go to File Explorer (one of the tabs on the right), go to /data/data/databases Select the database by just clicking on it. Go to the top right corner of the Android Device Monitor window. Click on the 'pull a file from the device' button: A window will open asking you where you want to save your database file. Save it anywhere you want on your PC. Android Studio versions >= 3.0: Open Device File Explorer via View > Tool Windows > Device File Explorer Go to data > data > PACKAGE_NAME > database, where PACKAGE_NAME is the name of your package (it is com.Movie in the example above) Right click on the database and select Save As.... Save it anywhere you want on your PC. Now, open the SQLiteBrowser you installed. Click on 'open database', navigate to the location you saved the database file, and open. You can now view the contents of your database.


选项2:

转到这个Github存储库,并按照自述文件中的说明在您的设备上查看您的数据库。你得到的结果是这样的:

就是这样。当然,在发布应用之前,你应该撤销所有这些步骤。

在Android 4.1 Canary 5预览版中引入了新的数据库检查器,您现在可以直接从IDE - https://developer.android.com/studio/preview/features?linkId=86173020#database-inspector检查、查询、修改和调试正在运行的应用程序中的SQLite数据库

支持数据库实时查询以及- https://developer.android.com/studio/preview/features?linkId=86173020#query

Android Studio从4.1版开始就绑定了一个数据库检查器。

但它有一个局限性:

数据库检查器仅适用于API级别26及更高的Android操作系统中包含的SQLite库。它不能与你的应用程序捆绑的其他SQLite库一起使用。

要知道sqlite数据库存储由你在android studio,你需要遵循简单的步骤:

1.Run your application
2.Go to Tools--->Android---->Device Monitor
3.Find your application name in left panel
4.Then click on File Explorer tab
5.Select data folder
6.Select data folder again and find your app or module name
7.Click on your  database name
8.On right-top window you have an option to pull file from device.
9.Click it and save it on your PC
10.Use FireFox Sqlite manager to attach it to your project.

欲了解更多信息,此链接将是有用的。 http://www.c-sharpcorner.com/UploadFile/e14021/know-where-database-is-stored-in-android-studio/

要查看您的db文件中的数据,您需要下载sqlite浏览器或在任何浏览器中添加相同的插件,因此您需要在浏览器中打开文件并查看您的数据。

从http://sqlitebrowser.org/下载浏览器

这里是屏幕截图显示浏览器包含注册数据库

谢谢,

我知道这个问题很老了,但我相信这个问题仍然存在。

从浏览器查看数据库

我创建了一个开发工具,你可以作为一个库集成到你的android应用程序项目。该工具在应用程序中打开一个服务器套接字,通过web浏览器进行通信。您可以浏览整个数据库并直接通过浏览器下载数据库文件。

集成可以通过jitpack.io完成:

项目build.gradle:

//...
allprojects {
    repositories {
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}
//...

应用build.gradle:

//...
dependencies {
    //...
    debugCompile 'com.github.sanidgmbh:debugghost:v1.1'
    //...
}
//...

安装应用程序类

为了只在特定的构建类型或产品风格中编译DebugGhostLib,我们需要一个抽象的Application类,它将以特殊的风格派生。把下面的类放在你的主文件夹(在java > your.app.package下):

public class AbstractDebugGhostExampleApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        // Do your general application stuff
    }
}

现在,对于您的发布构建类型(或产品风味),您将以下应用程序类添加到您的发布(或产品风味)文件夹(也在java > your.app.package下):

public class MyApp extends AbstractDebugGhostExampleApplication {
    @Override
    public void onCreate() {
        super.onCreate();
    }
}

这个应用程序类不会引用DebugGhostLib。

同时告诉AndroidManifest.xml你正在使用自己的应用程序类。这将在你的主文件夹中完成:

<manifest package="demo.app.android.sanid.com.debugghostexample" xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- permissions go here -->
    <application android:name=".MyApp"> <!-- register your own application class -->
        <!-- your activities go here -->
    </application>
</manifest>

现在,对于您的调试构建类型(或产品风味),您将以下应用程序类添加到您的调试(或产品风味)文件夹(也在java > your.app.package下):

public class MyApp extends AbstractDebugGhostExampleApplication {
    private DebugGhostBridge mDebugGhostBridge;

    @Override
    public void onCreate() {
        super.onCreate();

        mDebugGhostBridge = new DebugGhostBridge(this, MyDatabaseHelper.DATABASE_NAME, MyDatabaseHelper.DATABASE_VERSION);
        mDebugGhostBridge.startDebugGhost();
    }
}

你可以在这里找到工具。