乐闻世界logo
搜索文章和话题

How do I view the SQLite database on an Android device?

1个答案

1

In Android development, viewing SQLite databases is crucial for debugging and validating data. There are several methods to view and manage SQLite databases on Android devices:

1. Using Android Studio's Device File Explorer

Steps:

  1. Connect your device or use an emulator.
  2. In Android Studio, open View > Tool Windows > Device File Explorer.
  3. Navigate to data/data/<your app package name>/databases/.
  4. Right-click the database file and select Save As to save it to your computer.
  5. Use a SQLite database viewer, such as DB Browser for SQLite, to open and inspect the database file.

This method is straightforward and requires no additional setup.

2. Using Command-Line Tools

If you prefer the command line, use the adb tool to extract the database file.

Command:

bash
adb pull data/data/<your package name>/databases/<database name> <save location>/<filename>.db

Then, open the .db file with a SQLite database viewer.

3. Integrating Third-Party Libraries

Libraries like Stetho enable direct in-app database viewing.

Integration Steps:

  1. Add Stetho dependency to your build.gradle file:
    gradle

implementation 'com.facebook.stetho:stetho:1.5.1'

shell
2. Initialize Stetho in your application class: ```java public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); Stetho.initializeWithDefaults(this); } }
  1. Run your app and access chrome://inspect in Chrome to view and manage the database via Stetho.

This approach provides direct in-app database management.

4. Using Android Debug Database Library

The Android Debug Database library allows browser-based viewing of Android databases.

Integration Steps:

  1. Add the dependency:
    gradle

debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'

shell
2. Ensure your computer and Android device share the same network. 3. Run the app; the library prints a URL in Logcat. 4. Open the URL in a browser to view the database. By selecting these methods based on your preferences and needs, developers can efficiently diagnose issues and validate data on Android devices.
2024年7月21日 20:37 回复

你的答案