在外部设备查看数据表数据库ODF [英] View data tables odf database in external device

查看:188
本文介绍了在外部设备查看数据表数据库ODF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取和可视化我的外接设备内部数据库的数据表中的唯一方法是通过外部设备超级用户权限的特权归因理论?不存在另一种方式,使可视化的数据表作为模拟器?

The only way to get and visualize the data table of my database inside external devices is by atribution of privilege of superuser privilege in external device? Don't exist another way that allow visualize the data tables as in emulator?

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

I make this question because this way of superuser privilege not inspire me security.

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

Thanks for your attention (PS: Sorry by mistakes, but english is not my mother language :) )

推荐答案

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

You can add functionality to export the database file from the internal read-only app storage to the SD-Card by simply letting your app copy the file.

然后使用你有什么方法可以从那里得到它。可在任意设备和无需根上。

Then use whatever ways you have to get it from there. Works on any device and no root required.

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
        }
}

这篇关于在外部设备查看数据表数据库ODF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆