首页 > 解决方案 > Android 使用 Google Drive 将房间数据库文件的备份还原到 Android

问题描述

我尝试使用以下代码将房间数据库备份到谷歌驱动器。打开失败错误。有人请帮我确定问题吗?请分享链接或代码以备份房间数据库到谷歌驱动器

`文件存储文件 = 新文件();storageFile.setParents(Collections.singletonList("root")); storageFile.setName("sample_database");

    String fileId = "/data/data/packagename/databases/sample_database.db";
            java.io.File filePath = new java.io.File(fileId);

            FileContent mediaContent = new FileContent("",filePath);

            try {
                File file = mDriveService.files().create(storageFile, mediaContent).execute();
                System.out.printf("Filename: %s File ID: %s \n", file.getName(), file.getId());

            }

            catch(UserRecoverableAuthIOException e){

            }   ` 

标签: androidgoogle-drive-api

解决方案


推荐阅读