[Paid] 🛑 Google_Drive_API Extension to mange files with Google Drive

#Mr_Koder

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.

Entering:

first, you have to enable Google drive API and get ClientId , ClientSecret and refresh token from the Google Cloud console so you can watch this YouTube video :point_down:

All Blocks:

Screenshot 2023-09-09 172922

Screenshot 2023-09-09 172950

Screenshot 2023-09-09 173011


Documentation (Blocks)

component_set_get
SetClientId(String clientId):

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



component_set_get

SetClientSecret(String clientSecret):

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



component_set_get

SetRefreshToken(String refreshToken):

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



component_set_get

SetAccessToken(String accessToken):

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



component_set_get

GetAccessToken():

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



component_set_get

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.



component_set_get

AccessTokenObtained(String accessToken):

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



component_set_get

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.


component_set_get

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.



component_set_get

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.




component_set_get

FileUploadedFromURL

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




component_set_get

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.



component_method

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.



component_set_get

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.



component_set_get

DeleteFile(String fileId):

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



component_set_get

DeleteFolder(String folderId):

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



component_set_get

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.



component_set_get

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.




component_set_get

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.



component_set_get

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.



component_set_get

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.



component_set_get

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.



component_set_get

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.



component_set_get

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.



component_set_get

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_set_get

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.



component_set_get

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.



component_set_get

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.



component_set_get

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.




component_set_get

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.



component_set_get

.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.



component_set_get

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.



component_set_get

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.



component_set_get

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.



component_set_get

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.




component_method

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.

component_event

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.



component_set_get

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.



component_method

GetSdkVersion:


video:


AIX_File :

you can buy the GoogleDrive.aix file 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 problem you can DM me


This extension was tested on android 10 → 13


Thanks :stop_sign:

3 Likes

Can your extension steam 1 GB+ videos file?
I want to use in study app.

Yes, the Google Drive API supports uploading large video files, including those that are 1 GB or more in size. You can use the API to upload video files to Google Drive programmatically from your study app.

cause it supports resumable uploads. Resumable uploads allow you to upload files in smaller chunks or segments, making it possible to handle large files without the need to upload them in a single request.

2 Likes

I mean Download/steaming my all files is almost 1Gb+ in size and I want to play in my app. I have searched lots of api but it’s support less than 100mb only or thirparty website support not Google official. Did your extension support to play 1gb video file?

But this is not a video player Extension it is just extension to manage you files on Google Drive Cloud but

When it comes to streaming or playing large video files in your app, there are a few factors to consider:

  1. Video Format: Ensure that the video file you are trying to play is in a compatible format that is supported by your app and the video player you are using. Common video formats include MP4, AVI, MOV, and MKV.
  2. Streaming Protocol: Choose a streaming protocol that supports the efficient delivery of large video files. Popular streaming protocols include HTTP Live Streaming (HLS) and Dynamic Adaptive Streaming over HTTP (DASH).
  3. Network Bandwidth: Ensure that your app has sufficient network bandwidth to stream large video files smoothly. Lower bandwidth connections may result in buffering or degraded playback performance.
  4. Video Player: Select a video player component or library that can handle large file sizes and efficiently stream video content. There are several video player libraries available for different programming languages and platforms, such as ExoPlayer for Android