简体   繁体   English

Android Google Drive SDK:保存到应用程序文件夹

[英]Android Google Drive SDK: Saving to App Folder

For my current project, I would like to allow a user to create a sqlite database file and have them enter some content. 对于我当前的项目,我想允许用户创建一个sqlite数据库文件并让他们输入一些内容。 Then the user has the option to sign into their google drive account and upload this file. 然后,用户可以选择登录其Google云端硬盘帐户并上传此文件。 Afterwards, after the user makes further edits, the new database file is uploaded to replace the old file. 之后,在用户进行进一步编辑之后,将上载新的数据库文件以替换旧文件。 Finally, if the user has multiple devices, the database should be downloaded from the google drive and replace the existing file stored on the device. 最后,如果用户有多个设备,则应从google驱动器下载数据库,并替换存储在设备上的现有文件。

Currently, I have successfully setup Google Drive SDK authentication and I can sign in to the app with my account. 目前,我已经成功设置了Google Drive SDK身份验证,并且可以使用自己的帐户登录该应用。

My main question is, how do I upload a sqlite database file to the APP FOLDER when I choose to press a sync button? 我的主要问题是,当我选择按下同步按钮时,如何将sqlite数据库文件上传到APP FOLDER? (This method should be called when the user needs to sync) (当用户需要同步时,应调用此方法)

Additionally, how do I upload a sqlite database file to the APP FOLDER? 此外,如何将sqlite数据库文件上传到APP FOLDER?

Your question is a bit broad, but I'll try to send you in the right direction. 您的问题有点笼统,但我会尽力向您指出正确的方向。

First you have to decide if to use the REST Api or GDAA . 首先,您必须决定是使用REST Api还是GDAA Both will accomplish the same (actually the GDAA's functionality is a bit narrower now, but for your situation will do). 两者都将完成相同的工作(实际上,现在GDAA的功能要窄一些,但您的情况会做到)。 The big difference is that GDAA will handle on-line / off-line states for you, where with the REST Api, you have to implement some kind of non-UI thread (sync service) synchronization. 最大的不同是GDAA将为您处理在线/离线状态,而在REST Api中,您必须实现某种非UI线程(同步服务)同步。 Also, there are latency issues you must be aware when using GDAA. 此外,使用GDAA时,您还必须注意一些延迟问题。

Next, the process of uploading SQLite database is the same as any other binary data stream. 接下来,上传SQLite数据库的过程与任何其他二进制数据流相同。

  • Grab the 'xxx.db' file, make output stream (or byte[] buffer) and create a GooDrive file with title + mimetype metadata, push the stream into it's content and send it on it's merry way. 抓取“ xxx.db”文件,制作输出流(或byte []缓冲区),并创建一个包含title + mimetype元数据的GooDrive文件,将该流推送到其内容中,然后以一种愉快的方式发送。 The only difference between a standard folder and an app folder is the parent of the file. 标准文件夹和应用程序文件夹之间的唯一区别是文件的父文件夹。

  • You get an ID you can subsequently use to download the file to the device. 您将获得一个ID,随后可以使用该ID将文件下载到设备。 Or you can use search by metadata (title in your case) to get this ID. 或者,您可以使用按元数据搜索(在您的情况下为标题)来获取此ID。 Again it comes as input stream and you dump it to an 'xxx.db' file on your device. 同样,它作为输入流出现,您将其转储到设备上的“ xxx.db”文件中。

The second portion of your question deals with multiple devices. 问题的第二部分涉及多个设备。 None of the apis will notify you about a change in GooDrive, so you must implement one of the 2 strategies: 所有api都不会通知您有关GooDrive的更改,因此您必须实施以下两种策略之一:

1/ Polling (ouch), preferably in sync service with sync intervals the system gives you. 1 /轮询(哎呀),最好在系统为您提供同步间隔的同步服务中使用。

2/ GCM message broadcasted to the devices / users who are interested (not trivial, but efficient ... and sexy). 2 /向感兴趣的设备/用户广播了GCM消息(不是微不足道的,而是高效的……又性感)。

Another pitfall you must be aware when using multiple devices with GDAA is described in SO 29030110 and SO 22874657 . SO 29030110SO 22874657中描述了将多个设备与GDAA一起使用时必须意识到的另一个陷阱。

In case you decide to play with the 2 apis, I maintain basic CRUD implementation demos for both the REST and GDAA . 如果您决定使用这2个api,我将为RESTGDAA维护基本的CRUD实现示例 The GDAADemo has also an option to work with the app folder. GDAADemo还具有使用app文件夹的选项。

Good Luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM