【问题标题】:Google Drive Sqlite db upload not workingGoogle Drive Sqlite db上传不起作用
【发布时间】:2016-09-10 09:16:00
【问题描述】:

我想备份和恢复我的 sqlite 数据库。为此,我正在使用 google drive api。我使用了这个this 演示代码。一切都很完美。我可以上传和下载我的数据库,直到我卸载我的应用程序。

但后来我注意到一个奇怪的行为。场景如下

  • 向 sqlite 输入一些数据
  • 将我的 sqlite db 上传到驱动器
  • 卸载我的应用程序

  • 重新安装并尝试从驱动器下载文件。

    此时我无法从驱动器中找到任何文件....搜索总是返回 0...我不知道为什么。如果我不卸载应用程序并清除数据,一切都会完美。

这是我的上传代码......

public boolean createFile() {
        DriveId dId = null;
        String mimeType = MimeTypeMap.getSingleton().getExtensionFromMimeType("db");

        if (mGoogleApiClient != null && mGoogleApiClient.isConnected())
            try {
                DriveFolder pFldr = Drive.DriveApi.getAppFolder(mGoogleApiClient);
                if (pFldr != null) {
                    File file = context.getDatabasePath(db.getDatabaseName());
                    DriveContents cont = file2Cont(null, file);
                    MetadataChangeSet meta = new MetadataChangeSet.Builder().setTitle(Google_Drive_File).
                            setMimeType(mimeType).build();
                    DriveFolder.DriveFileResult r1 = pFldr.createFile(mGoogleApiClient, meta, cont).await();
                    DriveFile dFil = r1 != null && r1.getStatus().isSuccess() ? r1.getDriveFile() : null;
                    if (dFil != null) {
                        DriveResource.MetadataResult r2 = dFil.getMetadata(mGoogleApiClient).await();
                        if (r2 != null && r2.getStatus().isSuccess()) {
                            dId = r2.getMetadata().getDriveId();
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        return dId == null ? false : true;
    }

请帮帮我....

【问题讨论】:

  • 日志中是否还出现任何错误?请分享。
  • 没有没有错误

标签: android sqlite google-drive-android-api


【解决方案1】:

好吧,我已经解决了......我没有得到文件,因为我在身份验证证书中使用了调试密钥。一旦我通过发布更改我的调试密钥,所有工作都完美无缺。

【讨论】:

  • 嗨,你能帮我分享一下方法吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多