[Paid] :Star: GoogleDrive Extension to manage files with Google Drive

Introducing the Google Drive API Extension by Mr_koder

Overview:

The Google Drive API Extension, developed by Mr_koder, is a powerful tool that enables seamless integration with the Google Drive API within your Android applications. This extension provides a wide range of features and functionalities to enhance your app's file management capabilities. With this extension, users can effortlessly upload, edit, download, rename, move, and even change permissions of files and more on Google Drive.
Let's delve into the remarkable features of this extension and explore how it can revolutionize your app's file management capabilities.

Installing:

first, you have to Enable google Drive API and get ClientId and ClientSecret from the Google Cloud console so you can watch this video :point_down:

authenticate process preview:

All Blocks:




4


Documentation (Blocks)

SetClientId(String clientId):

  • Description: Sets the client ID for the Google Drive API.
  • Parameters:
    • clientId (String): The client ID to be set.



SetClientSecret(String clientSecret):

  • Description: Sets the client secret for the Google Drive API.
  • Parameters:
    • clientSecret (String): The client secret to be set.



SetRefreshToken(String refreshToken):

  • Description: Sets the refresh token for the Google Drive API.
  • Parameters:
    • refreshToken (String): The refresh token to be set.



SetAccessToken(String accessToken):

  • Description: Sets the access token for the Google Drive API.
  • Parameters:
    • accessToken (String): The access token to be set.



RequestGoogleOAuthDeviceCode:

Description:

Initiates the process of obtaining a device code from the Google OAuth2 API for authentication purposes.




GoogleOAuthDeviceCodeReceived Event:

Description:

Fired when the Google OAuth2 API returns a device code in response to the device code request.

Event Parameters:

  1. deviceCode (String): The device code for authentication.
  2. userCode (String): The user code associated with the device code.
  3. expiresIn (int): The duration in seconds for which the device code is valid.
  4. interval (int): The polling interval for checking token status.
  5. verificationUrl (String): The URL where the user can enter the user code for authentication.



GoogleOAuthErrorReceived Event:

Description:

Fired when the Google OAuth2 API returns an error in response to the device code request.

Event Parameters:

  1. errorType (String): The type of error returned by the Google OAuth2 API.
  2. errorDescription (String): A description of the error returned by the Google OAuth2 API.



GoogleOAuthRequestError Event:

Description:

Fired when an error occurs during the Google OAuth request, providing a general indication of an error.

Event Parameters:

  • errorMessage (String): The error message describing the issue encountered during the Google OAuth request.



ExchangeDeviceCodeForAccessToken Function:

Description:

Initiates the exchange of a device code for an access token in the Google OAuth process.




AccessTokenReceived Event:

Description:

Fired when an access token is successfully received from the Google OAuth token endpoint.

Event Parameters:

  1. accessToken (String): The obtained access token.
  2. expiresIn (int): The duration in seconds for which the access token is valid.
  3. refreshToken (String): The refresh token for obtaining a new access token.
  4. scope (String): The scope of access granted.
  5. tokenType (String): The type of token received.



AccessTokenErrorReceived Event:

Description:

Fired when an error occurs during the access token request to the Google OAuth token endpoint.

Event Parameters:

  1. errorType (String): The type of error returned by the Google OAuth token endpoint.
  2. errorDescription (String): A description of the error returned by the Google OAuth token endpoint.



AccessTokenRequestError Event:

Description:

Fired when an error occurs during the entire Google OAuth access token request process.







GetAccessToken():

  • Description: Retrieves the currently set access token.
  • Returns:
    • accessToken (String): The currently set access token.



GetAccessTokenWithRefresh():

  • Description: Retrieves the access token using the refresh token.
  • Implementation:
    • Creates an instance of the OkHttpClient class.
    • Builds the request body with the client ID, client secret, refresh token, and grant type.
    • Builds the HTTP request with the request URL and the previously created request body.
    • Enqueues the request with a callback for handling the response.
    • On successful response, extracts the access token from the JSON response and sets it as the current access token.
    • Notifies the main thread with the obtained access token using the AccessTokenObtained(String accessToken) method.
    • On failure or exception, notifies the main thread with an empty access token using the AccessTokenObtained(String accessToken) method.



AccessTokenObtained(String accessToken):

  • Description: Event triggered when an access token is obtained.
  • Parameters:
    • accessToken (String): The obtained access token.



blocks

UploadFile(String filePath, String folderId, String fileName, String mimeType):

  • Description: Uploads a file to Google Drive.
  • Parameters:
    • filePath (String): The local file path of the file to be uploaded.
    • folderId (String): The ID of the Google Drive folder where the file will be uploaded.
    • fileName (String): The desired name of the file on Google Drive.
    • mimeType (String): The MIME type of the file.


UploadProgress(int progress):

  • Description: Event triggered to provide progress updates during file upload.
  • Parameters:
    • progress (int): The current progress of the file upload, represented as a percentage.



FileUploaded(String fileId, String mimeType, String name, int responseCode):

  • Description: Event triggered when a file is uploaded.
  • Parameters:
    • fileId (String): The ID of the uploaded file.
    • mimeType (String): The MIME type of the uploaded file.
    • name (String): The name of the uploaded file.
    • responseCode (int): The HTTP response code indicating the upload status.



UploadFileFromURL

The UploadFileFromURL function uploads a file from a specified URL to Google Drive. It takes the file URL, folder ID, file name, and MIME type as parameters. The implementation of the function handles the necessary steps to upload the file, including opening the URL, reading the file content into a byte array, creating the request body, executing the HTTP request, and handling the response.




FileUploadedFromURL

The FileUploadedFromURL function is an event triggered when a file is successfully uploaded from a URL.




GetFileNameFromPath(String filePath):

  • Description: Retrieves the file name from a given file path.
  • Parameters:
    • filePath (String): The path of the file.
  • Returns:
    • fileName (String): The name of the file extracted from the file path.




StopUpload:

  • Description: stop and open the upload process.
    true for stop and false for open




UploadStopped:

  • Description: it fires after the uploading process stops.



GetMimeTypeFromPath(String filePath):

  • Description: Retrieves the MIME type from a given file path.
  • Parameters:
    • filePath (String): The path of the file.
  • Returns:
    • mimeType (String): The MIME type of the file.



blocks

DeleteFile(String fileId):

  • Description: Deletes a file from Google Drive.
  • Parameters:
    • fileId (String): The ID of the file to be deleted.



blocks

DeleteFolder(String folderId):

  • Description: Deletes a folder from Google Drive.
  • Parameters:
    • folderId (String): The ID of the folder to be deleted.



blocks

ItemDeleted(String itemId, int responseCode):

  • Description: Event triggered when an item (file or folder) is deleted.
  • Parameters:
    • itemId (String): The ID of the deleted item.
    • responseCode (int): The HTTP response code indicating the delete status.



blocks

CreateFolder(String folderName):

  • Description: Creates a folder in Google Drive.

  • Parameters:

    • folderName (String): The name of the folder to be created.
      createFolder(String folderName):
  • Description: Creates a folder in Google Drive.

  • Parameters:

    • folderName (String): The name of the folder to be created.
  • Implementation:

    • Creates an instance of OkHttpClient to handle the HTTP request.
    • Defines the JSON media type for the request body.
    • Builds the JSON string with the folder name and the MIME type for a folder.
    • Creates a request body with the JSON data.
    • Builds the HTTP request with the request URL, authorization header (including the access token), and request body.
    • Sends the request asynchronously using client.newCall(request).enqueue(...).
    • Handles the response in the callback.
    • On failure, logs the exception and triggers the FolderCreated event with empty values.
    • On success, extracts the folder ID, name, and MIME type from the JSON response and triggers the FolderCreated event with the obtained values.
  • Note: This function is used internally and not intended to be called directly by the user.




FolderCreated(String folderId, String folderName, String mimeType, int responseCode):

  • Description: Event triggered when a folder is created in Google Drive.
  • Parameters:
    • folderId (String): The ID of the created folder.
    • folderName (String): The name of the created folder.
    • mimeType (String): The MIME type of the created folder.
    • responseCode (int): The HTTP response code indicating the creation status.



ChangePermissions(String fileId, String role, String type):

  • Description: Changes the permissions of a file or folder in Google Drive.
  • Parameters:
    • fileId (String): The ID of the file or folder for which permissions will be changed.
    • role (String): The desired role for the new permission.
    • type (String): The type of the user or group to which the new permission will be applied.

Input options for type:

  • "user": Represents an individual user in Google Drive.
  • "group": Represents a group of users in Google Drive.
  • "domain": Represents a Google Workspace domain.
  • "anyone": Represents anyone with the link (public access).

Input options for role:

  • "owner": Grants the highest level of permission, allowing full control over the file or folder, including the ability to delete it.
  • "organizer": Similar to an owner, but specific to Google Workspace.
  • "fileOrganizer": Similar to an organizer but limited to files only.
  • "writer": Allows editing of the file or folder, but not managing permissions.
  • "commenter": Allows adding comments to the file or folder.
  • "reader": Provides read-only access to the file or folder.
  • "none": Removes the permission for the specified user or group.



PermissionsChanged(String kind, String id, String type, boolean allowFileDiscovery, int responseCode):

  • Description: Event triggered when the permissions of a file or folder are changed in Google Drive.
  • Parameters:
    • kind (String): The kind of the permission.
    • id (String): The ID of the permission.
    • type (String): The type of the user or group the permission is applied to.
    • allowFileDiscovery (boolean): Indicates whether the file discovery is allowed for the user or group.
    • responseCode (int): The HTTP response code indicating the permission change status.



RenameFileOrFolder(String fileId, String newName):

  • Description: Renames a file or folder in Google Drive.
  • Parameters:
    • fileId (String): The ID of the file or folder to be renamed.
    • newName (String): The new name to assign to the file or folder.



FileOrFolderRenamed(String kind, String id, String name, String mimeType, int responseCode):

  • Description: Event triggered when a file or folder is renamed in Google Drive.
  • Parameters:
    • kind (String): The kind of the file or folder.
    • id (String): The ID of the renamed file or folder.
    • name (String): The new name of the file or folder.
    • mimeType (String): The MIME type of the file or folder.
    • responseCode (int): The HTTP response code indicating the rename status.



ReplaceUploadedFile(String fileId, String newFilePath):

  • Description: Replaces an uploaded file in Google Drive with another file.
  • Parameters:
    • fileId (String): The ID of the file to be replaced.
    • newFilePath (String): The local file path of the new file to replace the existing file.



FileReplaced(String id, String name, String mimeType, int responseCode):

  • Description: Event triggered when a file is replaced in Google Drive.
  • Parameters:
    • id (String): The ID of the replaced file.
    • name (String): The name of the replaced file.
    • mimeType (String): The MIME type of the replaced file.
    • responseCode (int): The HTTP response code indicating the replace status.



component_method

ReplaceFileFromURL, is a public method that replaces a file in Google Drive with a file from a specified URL. It takes the following parameters:

  • fileId: The ID of the file to be replaced.
  • fileUrl: The URL of the file to replace with.
  • fileName: The name of the file.
  • mimeType: The MIME type of the file.



component_event(1)

FileReplacedFromURL, is an event triggered when a file is successfully replaced with a file from a URL. It takes the following parameters:

  • fileId: The ID of the replaced file.
  • mimeType: The MIME type of the replaced file.
  • fileName: The name of the replaced file.
  • responseCode: The HTTP response code of the file replacement operation.



GetFileSizeFromLocalPath(String localPath):

  • Description: Retrieves the file size of a file from its local path.
  • Parameters:
    • localPath (String): The local file path of the file.
  • Returns:
    • long: The file size in bytes, or -1 if the file does not exist or is not a regular file.



GetDirectDownloadLink(String fileId):

  • Description: Generates a direct download URL for a Google Drive file based on its file ID.
  • Parameters:
    • fileId (String): The ID of the Google Drive file.
  • Returns:
    • String: The direct download URL for the specified file.



GetAllFilesFromFolder(String folderId):

  • Description: Retrieves all files from the specified Google Drive folder.
  • Parameters:
    • folderId (String): The ID of the Google Drive folder.
  • Implementation:
    • Creates a new thread to perform the network request asynchronously.
    • Constructs the API URL to retrieve files from the specified folder using the provided folder ID.
  • Opens a connection to the URL and sets the request method to "GET".
  • Sets the authorization header using the access token.
  • Retrieves the response code, input stream, and reads the response content.
  • Converts the JSON response to a JsonObject using Gson.
  • Extracts the array of files from the JSON response.
  • Iterates over each file in the array and extracts the file ID, MIME type, and name.
  • Calls the AfterGetFiles event function on the main thread with the retrieved data.
  • Note: This function runs in a separate thread to avoid blocking the main UI thread.



AfterGetFiles(List<String> fileIds, List<String> mimeTypes, List<String> fileNames):

  • Description: Event triggered after retrieving files from the specified Google Drive folder.
  • Parameters:
    • fileIds (List of Strings): The list of file IDs.
    • mimeTypes (List of Strings): The list of MIME types of the files.
    • fileNames (List of Strings): The list of file names.




GetAllFoldersFromRoot():

  • Description: Retrieves all folders from the root directory of Google Drive.
  • Implementation:
    • Creates a new thread to perform the network request asynchronously.
    • Constructs the API URL to retrieve folders from the root directory.
    • Opens a connection to the URL and sets the request method to "GET".
    • Sets the authorization header using the access token.
    • Retrieves the response code, input stream, and reads the response content.
    • Converts the JSON response to a JsonObject using Gson.
    • Extracts the array of folders from the JSON response.
    • Iterates over each folder in the array and extracts the folder ID, MIME type, and name.
    • Calls the AfterGetFolders event function on the main thread with the retrieved data.
  • Note: This function runs in a separate thread to avoid blocking the main UI thread.



.AfterGetFolders(List<String> folderIds, List<String> mimeTypes, List<String> folderNames):

  • Description: Event triggered after retrieving all folders from the root directory of Google Drive.
  • Parameters:
    • folderIds (List of Strings): The list of folder IDs.
    • mimeTypes (List of Strings): The list of MIME types of the folders.
    • folderNames (List of Strings): The list of folder names.



MoveFileToFolder(String fileId, String newFolderId):

  • Description: Moves a file from one folder to another in Google Drive.
  • Parameters:
    • fileId (String): The ID of the file to be moved.
    • newFolderId (String): The ID of the new folder where the file should be moved.
  • Implementation:
    • Creates a new thread to perform the network request asynchronously.
    • Constructs the API URL to move the file by adding the new folder as a parent.
    • Opens a connection to the URL and sets the request method to "PATCH".
    • Sets the authorization header using the access token and content type header to "application/json".
    • Creates a JsonObject payload with the new folder ID.
    • Writes the payload to the connection's output stream.
    • Retrieves the response code, input stream, and reads the response content.
    • Converts the JSON response to a JsonObject using Gson.
    • Extracts the file name, ID, and MIME type from the JSON response.
    • Calls the AfterMoveFile event function on the main thread with the retrieved data.




AfterMoveFile(String fileName, String id, String mimeType, int responseCode):

  • Description: Event triggered after a file has been moved to a new folder.
  • Parameters:
    • fileName (String): The name of the moved file.
    • id (String): The ID of the moved file.
    • mimeType (String): The MIME type of the moved file.
    • responseCode (int): The HTTP response code indicating the success or failure of the move operation.



DownloadFileFromURL(String fileUrl, String localPath):

  • Description: Downloads a file from a given URL and saves it to the specified local path.
  • Parameters:
    • fileUrl (String): The URL of the file to be downloaded.
    • localPath (String): The local path where the downloaded file should be saved.
  • Implementation:
    • Creates a new thread to perform the download operation asynchronously.
    • Opens a connection to the file URL.
    • Checks if the connection response code is OK.
    • Retrieves the input stream and file length.
    • Creates a file at the specified local path and an output stream to write the downloaded data.
    • Reads the input stream and writes the data to the output stream.
    • Closes the streams and disconnects the connection.
    • Calls the handleDownloadResult function to handle the download result.
      handleDownloadResult(boolean success, String localPath, String errorMessage):
  • Description: Handles the result of a file download operation.
  • Parameters:
    • success (boolean): Indicates whether the download operation was successful.
    • localPath (String): The local path where the file was downloaded.
    • errorMessage (String): The error message, if any, encountered during the download operation.
  • Implementation:
    • Executes the handling logic on the main thread using the mainHandler.
    • Calls the AfterDownloadComplete event function with the download result.



AfterDownloadComplete(boolean success, String localPath, String errorMessage):

  • Description: Event triggered after a file has been downloaded.
  • Parameters:
    • success (boolean): Indicates whether the download operation was successful.
    • localPath (String): The local path where the file was downloaded.
    • errorMessage (String): The error message, if any, encountered during the download operation.



convertUriToFilePath(String uriString):

  • Description: Converts a file URI to a file path.
  • Parameters:
    • uriString (String): The string representation of the file URI.
  • Returns:
    • String: The file path corresponding to the given URI.
  • Implementation:
    • Parses the URI string into a Uri object.
    • Checks if the URI is a document URI using DocumentsContract.isDocumentUri(context, uri).
    • If it is a document URI, checks different document types using helper methods (isExternalStorageDocument, isDownloadsDocument, isMediaDocument) to determine the type of document and extract the relevant information.
    • Calls getDataColumn method to retrieve the file path using the content resolver and selection arguments.
    • If the URI scheme is "content", directly calls getDataColumn to retrieve the file path.
    • If the URI scheme is "file", returns the path directly from the URI.
    • If none of the conditions match, returns null.




CheckAccessTokenValidity

Description: Checks the validity of the access token and triggers an event with token details.

Usage:

  • Call this function to check the access token's validity.

AccessTokenValidityChecked Event

Description: Triggered when the access token's validity is checked, providing details about the token.

Parameters:

  • isValid (boolean): Indicates token validity.
  • accessType (string): Type of access granted.
  • expiresInSeconds (string): Remaining time until token expiration (seconds).
  • exp (string): Token expiration timestamp.
  • scope (string): Scope of access granted.
  • aud (string): Intended audience for the token.
  • azp (string): Authorized party for the token.



GetSdkVersion:



Authentication process

blocks

See also this graph


video:


AIX_File :

you can buy the GoogleDrive.aix and demo aia files from Here via PayPal and after you complete the payment you will be direclty redirected to the download URL of extension and if you faced any problems you can DM me


This extension was tested on android 10 --> 13


Thanks :stop_sign:

3 Likes

Files will be uploaded to user's own drive or to developer's drive? :thinking:

uploaded to user's own drive cause this extension to depend on Client id, client secret , accessToken, refresh token, and folder id of the user's drive

I don't see any blocks related to authentication which means files are uploaded to developer's drive.

I am sorry I misunderstood your mean yes you are right the extension uploads the files to developer's drive cause this is an API

New blocks added, now you can upload files from URL

New blocks were added to replace uploaded file by another one from its URL

New blocks added

How much per license?

Hello, the extension costs 8$ the extensions use your Google Drive credentials.
I don't understand what you mean by license!

New blocks added

:tada: Authentication blocks Added You can Now Authenticate the user’s account to use User'sGoogle Drive space

google drive block you account if you use like a server files for too much petitions to download files?

I didn't understand your question could you clarify it please

i would like to use the google drive for make a lot petitions for download. so if i use your extension i havent problems with google drive about block my connections of downloads

but this extension provides a wide range of features and functionalities to enhance your app's file management capabilities. With this extension, users can effortlessly upload, edit, download, rename, move, and even change permissions of files and more on Google Drive.

is your request to use it to download multiple files at the same time or something else?

is for get request for use like a ftp download files. a lot people download once for day maybe 1000 times for 1 day.

and yes multiple files maybe. but 1 file not multiple downloads.