Download Google Drive Files in Sketchware (Step-by-Step Guide)
In this tutorial, you will learn how to download files from Google Drive using Sketchware and save them directly into the Downloads folder on Android devices.
Step 1: Create a New Sketchware Project
Create a new project in Sketchware Pro.
Step 2: Make Google Drive File Public
Open Google Drive, select your file, and change its access to Public so it can be downloaded without permission issues.
Step 3: Design main.xml Layout
Add the following views inside main.xml:
- 2 EditText: edittext_drivelink, edittext_filename
- 2 TextView: text_id, text_link
- 3 Button: button_id, button_download, button_clear
Step 4: Add Internet Permission
Go to Permission Manager and enable the INTERNET permission.
Step 5: Create extractId More Block
Create a String more block named extractId(String url) to extract Google Drive file ID.
if (_url == null) return "";
String regex = "(?<=/d/|id=|folders/)[a-zA-Z0-9_-]{10,}";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(_url);
return matcher.find() ? matcher.group() : "";
Step 6: Create startDownload More Block
This block will download the file and save it to the Downloads folder.
DownloadManager.Request request =
new DownloadManager.Request(Uri.parse(_url));
request.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS,
_filename
);
request.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
);
request.allowScanningByMediaScanner();
request.setTitle("Downloading file");
request.setDescription(_filename);
DownloadManager dm =
(DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
dm.enqueue(request);
Step 7: Create Required Variables
- url
- id
- downloadUrl
- filename
Step 8: Extract Google Drive File ID
In button_id onClick, extract the ID and create the download URL:
https://drive.google.com/uc?export=download&id= + id
Step 9: Download File from Google Drive
In button_download onClick, call the startDownload block using downloadUrl and filename.
Step 10: Clear Input Fields
Use button_clear to reset all EditText and TextView values.
How to Use This App
Paste the Google Drive file link, click Extract ID, enter file name and tap Download.
0 Comments