Android Google Drive SDK: Saving to App Folder - java

For my current project, I would like to allow a user to create a sqlite database file and have them enter some content. Then the user has the option to sign into their google drive account and upload this file. 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.
Currently, I have successfully setup Google Drive SDK authentication and I can sign in to the app with my account.
My main question is, how do I upload a sqlite database file to the APP FOLDER when I choose to press a sync button? (This method should be called when the user needs to sync)
Additionally, how do I upload a sqlite database file to the 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. Both will accomplish the same (actually the GDAA's functionality is a bit narrower now, but for your situation will do).
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. Also, there are latency issues you must be aware when using GDAA.
Next, the process of uploading SQLite database is the same as any other binary data stream.
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. 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. Or you can use search by metadata (title in your case) to get this ID. Again it comes as input stream and you dump it to an 'xxx.db' file on your device.
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:
1/ Polling (ouch), preferably in sync service with sync intervals the system gives you.
2/ GCM message broadcasted to the devices / users who are interested (not trivial, but efficient ... and sexy).
Another pitfall you must be aware when using multiple devices with GDAA is described in SO 29030110 and SO 22874657.
In case you decide to play with the 2 apis, I maintain basic CRUD implementation demos for both the REST and GDAA. The GDAADemo has also an option to work with the app folder.
Good Luck

Related

Google Drive - push notifications content update - download

I have an application where user stores files (on the server) and on it's own google drive. I would like to reflect document changes from drive to server files. The only way of achieving this I could think of is using push notifications api for drive files and if type of notification is content update to download and replace file on server side. Is there a better way of achieving this, since notifications are being received often (almost for each letter typed) and downloading file every second doesn't seem like optimal solution.
There are many ways in which you can handle this ...
You can poll the Google Drive server for its state every minute. Figure out what changed and download it. This can help.
You can also use an existing tool or another one to solve this problem.

Java, Codename One: Exporting and -most importantly- importing files between users

Here the problem: my app will generate some files, and I want to give to the users the opportunity to exchange these files between them.
This requires 3 steps:
Saving the data: easily done in Storage implementing the
functions required by the Externalizable class;
Sharing the data: done (probably, right now it's impossible to check if the
result is correct because the missing step 3) with the sharing
methods offered by the framework, as soon as I understood I needed
to use as mimetype "application/octect-stream";
importing the downloaded data (shared by another user): this one I can't manage to
find a way to make it work. Loading the files from the app's Storage
is easy, but accessing to the folders out of the app's Storage is
something I can't manage to do.
I used FileSystemStorage in the hope of gaining access at least to the Download folder that (mostly) every phone has, but apparently I can't manage to accomplish the task
Using the FileSystemStorage on Android, for example, I have access to
/storage/emulated/0
/storage/emulated/legacy
file:///system
The first two being related to the Storage of the app.
Acceding to file:/// I obtain a long list of folders, a partial list including
media
logs
sdcard
Removable
...
root
...
But when I try to access some of these, they all appear to be empty. Either I make some mistake or the app can't see their content.
So I wonder if there is a way to accomplish the task, namely to have access to the files (probably in the Download folder) the user has downloaded, to import them.
Phone apps live in isolation within the phone. Android literally creates a separate Linux user for every app so they don't step on each other and damage the phone. iOS does similar tricks.
As a result apps can't just write a file to downloads and can't just list all the files there. This would violate the users privacy. So the native API to share a file is usually separate from the files API. We do have a share API in the CN class which lets you share images etc. to an arbitrary OS app. See isNativeShareSupported and share.
Ok, maybe I found a solution for reading the files from the Download folder in an extension of CodenameOne called FileChooser.
According to this blog post it should give access to, between the others, the Download folder (at least in Android).
I'm going to try it and, when everything is ready and tested, edit this reply to say how it worked out for me.

Download files from firebase storage and display it whenever required even when app is offline

I am developing an android app where students upload notes in pdf format and others download them. I am unable to figure out how to manage downloaded notes so I can show them when the app is offline, Do I need to maintain a Database of Downloaded files for it? How to avoid downloading notes again when required
Your question is a bit abstract. Still,
Of course downloading the same thing again again is an overhead on the network. As I see, your issue is with how to fetch the data to the viewers.
This might depend on what your 'note' type is and also its size. Also what your application is. (Webapp, Mobileapp)
Assuming that this is a mobile app and the notes are in the format of JPEG files;
You application can download it save it in the device storage. When fetching the downloaded information to the viewer, you can either fetch image by image from the storage location. Or else, just leave that to the end users themselves to decide a suitable app for that.(If your notes are in a generic format which is supported by explorer applications. No need to write an app to open PDFs.)
If your note uploaders have uploaded any revisions for the same file to your server, you can check for a hash value for your downloaded file and the server's available latest file. If the hash is of any different, then re-download. But if the revisions are maintained in the server with a good versioning mechanism, your mobile app can send the current version to the server, then the server will decide if a re-download is needed or not.

Android application performance with soap

i am building a application for a takeaway resturant using SOAP as a webservice.
Problem:
When i try to open the application it loads every time. and if i have slow internet it will take some time which is not good for a professional application.
How can i cache the images in my mobile so it loads automatically
Possible Solution in my mind:
i think i should use the local database and sink it with internet
Use local cache system (but what if the application close).
Use arraylist to store information.
Can you guide me in that as i am stuck i do some reading but i don't feel any reliable solution on it.
You can use some libs but you can lose images if the app is closed.
Actually you can cache images with libs and save them to sdcard at the same time. You need to save Their id in database. Then take data from sdcard by id from database in case you haven't internet.

Determine whether to use internal or external android app

Ive been reading up on where to store my files, and I am still not sure what route I should take. I am writing an application that will store images and pdf's (totaling 300MB or so). I would like the app installed on the internal storage, and then allow the user to store the pdfs and some images on there choice of storage. Is it possible to allow the user to choose which storage they use for those files only even I have this in my manifest:
android:installLocation="internalOnly"
Essentially I would like to have the user choose this when the applications start.
If it is, would I just need to have a flag in application that if the user chose external and if the external storage was available, had enough space, then save files to it. Every time the user opened the app I would check to make sure the files are available. If the users chose internal it would use openFileOutput. Does this all seem right, is this possible?
Or should I just consider making it completely internal only, because without these PDF's and images the app is not usable.
It sounds like you can set the installLocation as following to accomplish exactly what you want:
android:installLocation="preferExternal"
From the documentation:
If you declare "preferExternal", you request that your application be
installed on the external storage, but the system does not guarantee
that your application will be installed on the external storage. If
the external storage is full, the system will install it on the
internal storage. The user can also move your application between the
two locations.
If you set it to internalOnly, the user cannot move the application from internal storage to external storage, so above solution is probably your best option.

Categories

Resources