自应用发布以来,我一直在使用Android Studio开发应用。
直到最近,一切都很好,我必须调试和检查数据库文件。由于我不知道如何直接看到数据库,当我调试生成数据库文件时,我不得不将数据库文件从我的手机导出到PC上。
为此,我必须打开DDMS >文件资源管理器。一旦我打开DDMS,我必须重新连接USB,我失去了调试线程。在检查数据库文件之后,我必须关闭DDMS并重新连接USB以回到调试模式。
这太复杂了。有人有更好的方法来做到这一点在Android Studio(我知道它更容易在Eclipse) ?
从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存储库,并按照自述文件中的说明在您的设备上查看您的数据库。你得到的结果是这样的:
就是这样。当然,在发布应用之前,你应该撤销所有这些步骤。