在外部设备中获取和可视化我的数据库的数据表的唯一方法是通过外部设备中超级用户权限的权限的归属?不存在另一种允许在模拟器中可视化数据表的方式吗?
我提出这个问题是因为这种超级用户特权方式不会激发我的安全感。
感谢您的关注(PS:对不起,错了,但英语不是我的母语:))
您可以添加功能,将数据库文件从内部只读应用存储导出到 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
}
}