I have an android app that reads spreadsheets from google drive and shows it to the user as a contact list. It is design to be a phone list you can send to your team members.
https://play.google.com/store/apps/details?id=com.ctw.cloudpeepsfree
Anyway, to get to work, all of the Google drive file names need to begin with prefix "peep:". I have heard rumors that with the latest versions of Google Drive API, I should be able to instead put all of my app files into a special folder that only my application can read. I was looking for some sample code or article on this subject. Thanks...
found this blog:
http://googleappsdeveloper.blogspot.com/2013/04/more-ways-for-apps-to-write-to-drive.html
You can use application data folder in your case, but use won't be able to list the file you put it on appdata folder: https://developers.google.com/drive/appdata
In order to put a file in the appdata folder, just set its parent to "appdata":
File body = new File();
body.setTitle(title);
body.setDescription(description);
body.setMimeType(mimeType);
body.setParents(Arrays.asList(new ParentReference().setId("appdata"));
service.files().insert(body).execute();
Related
in google drive, there's a tab named "backups" that contains data from old android phones I have.
These backups are not downloadable.
Is there a way to download these backup files? is there a way to get the information inside the backup files? ( API requests )
I know that for the Whatsapp backup-file there is a different API (because it's not downloadable like the others).
There's no mention of accessing the backup folder in Drive API. But, if you're referring to a special folder called App Folder which is only accessible by your application, then you can. Check the Get authorization to use the App Folder.
I've started using the Google Drive Android API in my app and have managed to get it to create files and save them to the app folder.
Is there any way I would be able to view these files in Google Drive, so I can check their contents (to check for bugs)?
No, per the App Folder documentation:
The App Folder is a special folder that is only accessible by your application. Its content is hidden from the user and from other apps
You can, of course, add a debugging mode/UI to display the files within your own app.
I tried following both the documentation:
https://developers.google.com/drive/android/pinning
And the demo:
https://github.com/googledrive/android-demos/blob/master/app/src/main/java/com/google/android/gms/drive/sample/demo/PinFileActivity.java
but I am still very confused on how to sync a pinned file between my local device and Google Drive.
According to the documentation:
Pinning a file causes the latest version of that file's contents and metadata to be downloaded to the local device whenever a new version is available.
I implemented the code provided, but they only show to set a file as "pinned" without more explanation.
When and where do we specify where those pinned files must be downloaded on the local device?
I created test files that are well listed in the remote Google Drive, but I have no idea how those pinned files can be retrieved automatically on the local device as explained in the guide.
The demos provided are just too simple and limited...
I actually succeeded to accomplish what I wanted, I had to understand how it worked through several tests.
In my app I actually use the specific app folder to interact with Google Drive:
Drive.DriveApi.getAppFolder(mGoogleApiClient)
This folder on Google Drive is accessed by the app only.
At first I thought I had to specify a folder on my device to indicate where the files from the Google Drive app folder should be downloaded but it does not work that way.
You just have to access this app folder directly and check if there were any changes inside it since the last time it was accessed.
So basically when the files were changed I copy them where I need in my app file structure.
I am writting an app with an instant messenger function. Users would write text or share images in the IM function. The text data and file name of images are stored in the sqlite file while the images are stored in the device.
Since my server will not keep the data, the user would not get the chat record when he / she switches to a new device. With reference to whatsapp, they allow the users to back up the chat records and images to Google Drive on a regular basis and get the data back from the drive as shown in the picture below.
When I go to my own google drive, I would find "Whatsapp" is connected to my google drive as shown below.
I am new to the Google Drive API in Android and I would like to backup my sqlite database and images in the same way as Whatsapp does. I know there are few questions related to the back-up of sqlite database to Google Drive but it seems that it only contains part of the codes and this makes the beginner quite difficult to understand.
Will there be any sample projects on github, questions on stackoverflow or tutorials that would allow me learn how to back up sqlite database and images programmatically in Android step by step?
In additions, I am surprised to see only whatsapp is connected to my Google Drive but no more other apps, so I don't know if third-party developers would have the same access to Google Drive and complete the backup in the same way as Whatsapp.
Have you seen https://github.com/googledrive/android-demos?
I think you need to follow "Create a file in App Folder" to save your sqlite file in the user's hidden AppData folder.
To retrieve the file back you could query the AppData folder (make sure to call requestSync() before querying to ensure the cache is up-to-date).
This is certainly doable. You will need to learn how to upload files to Google Drive programmatically.
Will there be any sample projects on github, questions on stackoverflow or tutorials that would allow me learn how to back up sqlite database and images programmatically in Android step by step?
There are several samples like:
Tutorials: Try this Java Quickstart for uploading to Drive since you're going to do it in Android.
An example of saving files to Google Drive SDK in Android.
Github samples for Android and Drive SDK.
For uploading images, note that you will be using an image mimetype like image/png for .png and image/jpeg for .jpg files.
For uploading sql database to Drive, here's a snippet from this sample.
String mimeType = MimeTypeMap.getSingleton().getExtensionFromMimeType("db");
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle(GOOGLE_DRIVE_FILE_NAME) // Google Drive File name
.setMimeType(mimeType)
.setStarred(true).build();
// create a file on root folder
Drive.DriveApi.getRootFolder(api)
.createFile(api, changeSet, result.getDriveContents())
.setResultCallback(backupFileCallback);
I have been trying to integrate google drive sdk in my android application. It all seems to work fine but now i have a requirement where in i would like to list out all the files with the same extension. For example I would like to get a list of all JPG files that the user might have saved to his google drive.
For doing this i tried to use the following
FileList temp = service.files().list().setQ("title contains 'jpg'").execute();
But this does not return me anything.
On the other hand if i replace jpg with one of the words in the file name then it seems to work fine. So strangely a search on extension is not working while a search on the main name seems to work
Is this functionality broken with the drive sdk or am i missing something here?
Google Drive determines file types based on their mimeType attribute, not their extension. Instead of looking at the file name, try something like:
FileList temp = service.files().list().setQ("mimeType = 'image/jpeg'").execute();
From the comment left by Burcu Dogan it is clear that at this point of time querying based on file extensions is not possible. Will have to wait for an update to the google drive sdk to include such functionality.
Putting this out as a note to help anyone who might be facing a simialr issue and looking for a solution.