小编Its*_*wan的帖子

数据库导入和导出在Android Pie中不起作用

以下是导入和导出SQLite数据库的工作方法。在除Android Pie外的所有android版本中,其工作情况都很好。当我尝试导入Android Pie时,它显示成功的Toast,但未还原数据库。谁能帮我解决Android Pie(API 28)问题。

private void importDB() {

    try {
        File sd = Environment.getExternalStorageDirectory();
        File cur_db_pat = new File(this.getDatabasePath(DATABASE_NAME).getAbsolutePath());

        if (sd.canWrite()) {
            String backupDBPath = bac_dir_nam +"/" + DATABASE_NAME;
            File currentDB = new File(sd, backupDBPath);

            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(cur_db_pat).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();
            Toast.makeText(getBaseContext(), cur_db_pat.toString(),
                    Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {

        Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG)
                .show();

    }
}

private void exportDB() {

    try {
        File sd = Environment.getExternalStorageDirectory();
        File cur_db_pat = new …
Run Code Online (Sandbox Code Playgroud)

java sqlite android android-9.0-pie

5
推荐指数
2
解决办法
1423
查看次数

标签 统计

android ×1

android-9.0-pie ×1

java ×1

sqlite ×1