Android - viewing SQLite databases on device?

前端 未结 4 756
春和景丽
春和景丽 2020-12-19 04:36

Is there any tool that will allow me to browse databases on my Android device? Something like Sql Management Studio - you know GUI tool that displays databases, tables, row

4条回答
  •  星月不相逢
    2020-12-19 05:08

    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

     
    

提交回复
热议问题