2012-08-30 42 views
0

在外部设备中获取和可视化数据库数据表的唯一方法是通过在外部设备中授予超级用户特权的特权?不存在另一种允许在仿真器中可视化数据表的方式?在外部设备中查看数据表odf数据库

我提出这个问题是因为这种超级用户权限的方式不能激发我的安全性。

感谢您的关注(PS:由错误很抱歉,但英语不是我的母语:))

回答

0

您可以添加功能,从内部只读应用存储在数据库文件导出到SD-通过简单地让你的应用程序复制文件。

然后用任何方法从那里得到它。适用于任何设备,无需root。

private void exportDb() { 
    File database = getDatabasePath("myDb.db"); 
    File sdCard = new File(Environment.getExternalStorageDirectory(), "myDb.db"); 
    if (copy(database, sdCard)) { 
     Toast.makeText(this, "Get db from " + sdCard.getPath(), Toast.LENGTH_LONG).show(); 
    } else { 
     Toast.makeText(this, "Copying the db failed", Toast.LENGTH_LONG).show(); 
    } 
} 

private static boolean copy(File src, File target) { 
    // try creating necessary directories 
    target.mkdirs(); 
    boolean success = false; 
    FileOutputStream out = null; 
    FileInputStream in = null; 
    try { 
     out = new FileOutputStream(target); 
     in = new FileInputStream(src); 
     byte[] buffer = new byte[8 * 1024]; 
     int read; 
     while ((read = in.read(buffer)) != -1) { 
      out.write(buffer, 0, read); 
     } 
     success = true; 
    } catch (FileNotFoundException e) { 
     // maybe log 
    } catch (IOException e) { 
     // maybe log 
    } finally { 
     close(in); 
     close(out); 
    } 
    if (!success) { 
     // try to delete failed attempts 
     target.delete(); 
    } 
    return success; 
} 

private static void close(final Closeable closeMe) { 
    if (closeMe != null) 
     try { 
      closeMe.close(); 
     } catch (IOException ignored) { 
      // ignored 
     } 
}