Storing Application Data

The Google Drive API includes a special hidden folder that your app can use to store application specific data.

What is the App Folder?

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. Despite being hidden from the user, the App Folder is stored on the user's Drive and therefore uses the user's Drive storage quota. The App Folder can be used to store configuration files, temporary files, or any other types of files that belong to the user but should not be tampered with.

Even though users can't see the App Folder's content, they can see the amount of storage used by your App Folder in the Manage Apps dialog:

Manage apps dialog showing Application Data folder size

Your App Folder is deleted if users uninstall your app from their Drive. They can also delete your app's App Folder manually using the Options menu in the Manage Apps dialog.

Get authorization to use the App Folder

To be able to use your App Folder, your application must request the SCOPE_APPFOLDER scope as part of authorization.

Get the App Folder

The App Folder can be retrieved by using the DriveApi.getAppFolder method. It can then be used similarly to a normal folder. For example, you can use the DriveFolder.listChildren method to list the files in the App Folder.

Check if a file or folder is in the App Folder

You can check whether a file or folder is in the App Folder by retrieving its metadata. The Metadata.isInAppFolder method returns true if the file or folder is in the App Folder.

Create a file in the App Folder

Creating a file in the App Folder is the same as for a normal folder. The following example demonstrates creating a new text file named appconfig.txt in the App Folder:

final private ResultCallback<DriveContentsResult> contentsCallback =
        new ResultCallback<DriveContentsResult>() {
    public void onResult(DriveContentsResult result) {
        if (!result.getStatus().isSuccess()) {
            showMessage("Error while trying to create new file contents");

        MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                .createFile(getGoogleApiClient(), changeSet, result.getDriveContents())

For a full working example, see the CreateFileInAppFolderActivity sample in the Google Drive Android API Demos app.

Send feedback about...

Drive API for Android
Drive API for Android