0

外部デバイス内のデータベースのデータテーブルを取得して視覚化する唯一の方法は、外部デバイスのスーパーユーザー特権の特権を割り当てることです。エミュレータのようにデータテーブルを視覚化できる別の方法はありませんか?

このスーパーユーザー特権の方法は私にセキュリティを刺激しないので、私はこの質問をします。

ご清聴ありがとうございました(PS:間違いで申し訳ありませんが、英語は私の母国語ではありません:))

4

1 に答える 1

0

アプリにファイルをコピーさせるだけで、データベースファイルを内部の読み取り専用アプリストレージからSDカードにエクスポートする機能を追加できます。

次に、そこから取得するために必要な方法を使用します。どのデバイスでも動作し、ルートは必要ありません。

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
        }
}
于 2012-08-30T18:17:08.813 に答える