How to enable download in webview in Sketchware apps?
How to enable download in an app created with Sketchware?
Suppose you have created an app in Sketchware which uses webview to open a site. You can seamlessly explore the site in your app. But the download links in the webview field do not work.
But it is possible to make it work by exporting the source code. You can edit the code in either Android studio or Eclipse to add your desired features and then recompile it. I tried to do that but soon realized that setting up environment for development of Android app is not easy for a naive like me. But it can be done by code injection or by using another mobile app called Anacode.
Enabling download from webview in Sketchware using add source directly block.
1. In VIEW area of your app insert a WebView (webview1).
2. In LOGIC area, in onCreate event,
a. Add write String... to file path ... Block. This will add WRITE_EXTERNAL_STORAGE permission.
b. Then add an add source directly block. In this block put following code:
Enabling download from webview in Sketchware using add source directly block.
1. In VIEW area of your app insert a WebView (webview1).
2. In LOGIC area, in onCreate event,
a. Add write String... to file path ... Block. This will add WRITE_EXTERNAL_STORAGE permission.
b. Then add an add source directly block. In this block put following code:
webview1.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity (intent);
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity (intent);
}
});
The above code will enable download using Chrome. To download directly, use following code.
webview1.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
try {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype));
request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
java.io.File aatv = new java.io.File(Environment.getExternalStorageDirectory().getPath() + "/Download");
if(!aatv.exists()){if (!aatv.mkdirs()){ Log.e("TravellerLog ::","Problem creating Image folder");}}
request.setDestinationInExternalPublicDir("/Download", URLUtil.guessFileName(url, contentDisposition, mimetype));
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
showMessage("Downloading File....");
//Notif if success
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
showMessage("Download Complete!");
unregisterReceiver(this);
}};
registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
} catch (Exception e){
showMessage(e.toString());
}
}
});
c. After this add webview loadUrl block and write the url you intend to load in webview.
4. Save and run the project.
});
The above code will enable download using Chrome. To download directly, use following code.
webview1.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
try {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype));
request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
java.io.File aatv = new java.io.File(Environment.getExternalStorageDirectory().getPath() + "/Download");
if(!aatv.exists()){if (!aatv.mkdirs()){ Log.e("TravellerLog ::","Problem creating Image folder");}}
request.setDestinationInExternalPublicDir("/Download", URLUtil.guessFileName(url, contentDisposition, mimetype));
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
showMessage("Downloading File....");
//Notif if success
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
showMessage("Download Complete!");
unregisterReceiver(this);
}};
registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
} catch (Exception e){
showMessage(e.toString());
}
}
});
c. After this add webview loadUrl block and write the url you intend to load in webview.
4. Save and run the project.
For how to enable upload from webview in Sketchware, visit the link below:
http://www.sketchwarehelp.com/2017/10/how-to-enable-upload-from-webview-in.html
With this encoding will I be able to download it internally with my browser?
ReplyDelete1. Now code Injection is not possible in Sketchware.
ReplyDelete2. With this code, download link will open in any app in your mobile which has download mananager, e.g. Google Chrome, UC browser, etc.
Bro how to add mp4 video in sketchware
DeleteHoe to export souce
ReplyDeleteThere is an option to export source code in Sketchware, in project options. It is paid feature now.
DeleteWe can export by watching ad also
DeleteHow to add source direckly
ReplyDeleteCode Set string to yes/no
why I can't paste code, in add source directly? please help me...
ReplyDeleteHow can i save image by long press please..
ReplyDeleteI really enjoyed this post. You describe this topic very well. I really enjoy reading your blog and I will definitely bookmark it! Keep up the interesting posts!
ReplyDeleteFood Service Worker
Food Service Worker Course
Food Service Worker Training Program
Office Administration Course
Off ice Administration Certificate
Off ice Admin Course
Food Handlers Certificate
Food Handling Course
How to read and download PDF file from webpage on Sketchware. Pls help out.
ReplyDeleteTry putting this code in onCreate
Deletewebview1.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity (intent);
}
});
I can download the pdf, but i can not use the pdf directly. Do you have a solution, sir?
DeleteHow can I add pdf files in my app made by sketchware
ReplyDeleteuse a file file picker using json block
DeleteI can still inject code in the latest version.The block is in the operator section
ReplyDeleteHow to download an image using 'set image from url' block ?
ReplyDeleteThe article that you have been shared is very awesome. This is a very nice compilation, possibly the best on the web. Hope to see more useful information from this site...
ReplyDeleteIelts reading practice test |
Ielts reading practice |
Ielts general reading practice test |
Excellent post. It is one of the best post from other. It is a useful and charming post. I want to sharing this topic with some of my close friends. So thanks this post.
ReplyDeleteIelts listening practice test |
Ielts listening practice |
I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.
ReplyDeleteIelts writing samples |
Ielts general writing task 1 |
Ielts general writing task 2 |
Ielts writing task 2 |
Ielts writing task 1 |
writing task 1 general |
writing ielts general |
Thank you. I just found this blog and what a great resource! It is a good blog and their posts are effective. This is very nice post! I will bookmark this blog.
ReplyDeleteIelts speaking topics |
Ielts speaking questions |
Ielts speaking sample |
Ielts speaking tips |
Thanks,some great data here keep up the good work. I actually allow for a more creative comment as I'm a bit out of my deph but I will be checking back here for further updates.
ReplyDeleteFood Service Worker |
Food Service Worker Course |
Food Service Worker Training Program |
food service certification |
food service worker school near me |
food service worker diploma |
food service worker course near me |
food service diploma |
food service careers |
food service worker certificate |
food service worker course online |
food service certificate |
food service training |
food service course |
food service worker program |
food service certificate ontario |
food server coursess |
I just came across your blog and reading your beautiful words. I thought I would leave my first comment but I don't know what to say except that I have enjoyed reading.
ReplyDeleteOffice Administration Course |
Office Administration Certificate |
Office Admin Course |
The content which is found in this article was very cordial. I really liked it very much. Thanks a lot for posting such an informative site in this post. Thanks a lot!
ReplyDeleteFood Handlers Certificate |
Food Handling Course |
I felt very happy while reading this site. This was really very informative site for me. I really liked it. This was really a cordial post.
ReplyDeleteIELTS Test |
IELTS Test Centre |
IELTS Test Dates |
IELTS Academic Test |
IELTS Test Fee |
British Council IELTS |
IELTS Mississauga |
IELTS Brampton |
IELTS Test Booking |
IELTS Registration |
Book IELTS |
It's showing no permission to write to sdcard. But I have given storage permission.
ReplyDeleteCan I download Facebook video with this
ReplyDeleteHow to block redirecting pages in webview page
ReplyDeleteThis only enabled in one of webviews. I have like 5 on my project. So yea, i need on all 5 of them. Also if i add same code to others it will just give error about syntax and stuff.
ReplyDeleteHi, I have fixed the ability to download the image from the web, but the links to the sites are no longer displayed in the edit text, and the progress bar has also failed. Please tell me what to do to fix it.
ReplyDeletegreet. but i try script in top. downlad succes but extention file .apk where i change
ReplyDeleteThis comment has been removed by the author.
ReplyDelete