开发者

Android - viewing SQLite databases on device?

开发者 https://www.devze.com 2022-12-31 06:20 出处:网络
Is there any tool that will allow me to browse databases on my Android device? Something like Sql Management St开发者_如何转开发udio - you know GUI tool that displays databases, tables, row in tables,

Is there any tool that will allow me to browse databases on my Android device? Something like Sql Management St开发者_如何转开发udio - you know GUI tool that displays databases, tables, row in tables, etc.

I'm using Eclipse for development (if it is important for plug-in suggestions).

Thanks!


First of all, you will not be able to 'browse' the databases unless you logged in as root (there are several tutorials out there that explains how to get root on Android). Secondly, you can use adb shell (adb is included into the SDK), and when you are there you can use the sqlite3 command to browse the databases.

Of course, sqlite3 does not provide a GUI... but, you can copy the database you want to browse to your computer and use any GUI for sqlite there.


Yes we can do this but in different way.Using this logic you will get database in SDcard.

        String sourceLocation = "/data/data/com.sample/databases/yourdb.sqlite" ;// Your database path
        String destLocation = "yourdb.sqlite";
        try {
            File sd = Environment.getExternalStorageDirectory();
            if(sd.canWrite()){
                File source=new File(sourceLocation);
                File dest=new File(sd+"/"+destLocation);
                if(!dest.exists()){
                    dest.createNewFile();
                }
                if(source.exists()){
                    InputStream  src=new FileInputStream(source);
                    OutputStream dst=new FileOutputStream(dest);
                    // Copy the bits from instream to outstream
                    byte[] buf = new byte[1024];
                    int len;
                    while ((len = src.read(buf)) > 0) {
                        dst.write(buf, 0, len);
                    }
                    src.close();
                    dst.close();
                }
            }
            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }

You have to give permission

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


My suggestion is to run your app on emulator (so you could copy db file right from ADT File Explorer) and then view it with SQLite Manager Firefox plugin.


You can download a plugin "com.questoid.sqlitebrowser_1.2.0"....Just pop it in google and download it. From the drop it on to the eclipse running folder, under the plugins folders. When you run the app on the emulator, you will be able to view all the database information on the DDMS section.

0

精彩评论

暂无评论...
验证码 换一张
取 消