无法打开Android Device Monitor,如何查看Android SQLite数据库数据?
Hey there! I totally get the frustration with Android Device Monitor being deprecated and not working when you need to grab your SQLite database file for DB Browser for SQLite. Let’s break down the best, most reliable alternatives you can use right now:
1. Use Android Studio’s Built-in Device File Explorer
This is the easiest, most straightforward option since it’s already integrated into Android Studio:
- Open Android Studio, head to the View menu → Tool Windows → Device File Explorer
- Navigate to the path:
data/data/[your-app’s-package-name]/databases/(replace the package name with your app’s actual package, likecom.yourname.yourapp) - Right-click your database file (it’ll typically end with
.db) and select Save As to download it to your local computer - Once saved, you can open this file directly in DB Browser for SQLite
2. Pull the File via ADB Commands
If you prefer using the terminal for more control, the Android Debug Bridge (ADB) works perfectly:
- First, confirm your device or emulator is connected by running this command in your terminal:
adb devices - Then pull the database file to your local machine with:
adb pull /data/data/[your-app-package-name]/databases/[your-db-filename].db /path/to/your/local/folder - After the file is pulled, open it in DB Browser like you would any local SQLite file
3. Add a Debug Export Feature to Your App
If you need to access the database frequently during development, adding a quick export feature to your debug build can save you time:
- Add a hidden debug button or a menu option that copies the database file to your device’s external storage (like the Downloads folder)
- Here’s a quick Kotlin snippet to do this (make sure to add the necessary storage permissions for debug builds):
// Add this to a debug-only activity or utility class fun exportDatabaseToStorage() { val dbSourcePath = "/data/data/${packageName}/databases/your-db-name.db" val dbDestPath = "${externalCacheDir?.absolutePath}/your-db-name-exported.db" val sourceFile = File(dbSourcePath) val destFile = File(dbDestPath) if (sourceFile.exists()) { sourceFile.copyTo(destFile, overwrite = true) // Show a toast or log message to confirm the export Toast.makeText(this, "Database exported to ${destFile.path}", Toast.LENGTH_LONG).show() } } - Once exported, you can grab the file from your device’s storage and open it in DB Browser
4. Use Stetho for In-Browser Database Viewing
If you don’t want to export the file at all, Facebook’s Stetho tool lets you view your SQLite database directly in Chrome:
- Add these dependencies to your app’s
build.gradle(only for debug builds to avoid bloating release builds):debugImplementation 'com.facebook.stetho:stetho:1.5.1' debugImplementation 'com.facebook.stetho:stetho-sqlite:1.5.1' - Initialize Stetho in your Application class (wrap it in a debug check to keep release builds clean):
class MyApp : Application() { override fun onCreate() { super.onCreate() if (BuildConfig.DEBUG) { Stetho.initializeWithDefaults(this) } } } - Run your app, open Chrome, and navigate to
chrome://inspect - Select your app from the list, click "Inspect", then go to the Resources tab → find SQLite to browse your database tables, run queries, and view data directly in the browser
内容的提问来源于stack exchange,提问作者Payal Ahuja

