Download google drive link in Sketchware

This post shows how to download files from Google Drive in Sketchware to Downloads folder.

1. Create a new project in Sketchware pro.

2. In google drive, make access of your files public.

3. In main.xml add two EditText edittext_drivelink, edittext_filename; two TextViews text_id, text_link, and three Buttons button_id, button_download, button_clear.

4. In Permission manager, add INTERNET permissions.

5. Create a more block of type String, name extractId [String url]. Put following codes in it.

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() : "";
6. Create a more block startDownload [String url][String filename] and put following codes in it.

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);

7. Create four String variables url, id, downloadUrl, filename.

8. In button_id onClick event, extract id from url and create downloadUrl by joining https://drive.google.com/uc?export=download&id= and id.

9. In button_download onClick event, download the file using downloadUrl and filename.

10. In button_clear onClick event, reset all TextViews and EditText.

11. Save and run the project.

12. In edittext_drivelink, paste google drive link of your file and click Extract Id. Then write file name and click Download.

Comments

Popular posts from this blog

Simple car racing android game in Sketchware

How to enable upload from webview in Sketchware?

Simple Audio recorder app in Sketchware

Retrieve contact list in Sketchware

Custom dialog box in Sketchware using CustomView