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

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

Comments

  1. With this encoding will I be able to download it internally with my browser?

    ReplyDelete
  2. 1. Now code Injection is not possible in Sketchware.

    2. With this code, download link will open in any app in your mobile which has download mananager, e.g. Google Chrome, UC browser, etc.

    ReplyDelete
  3. Replies
    1. There is an option to export source code in Sketchware, in project options. It is paid feature now.

      Delete
    2. We can export by watching ad also

      Delete
  4. How to add source direckly
    Code Set string to yes/no

    ReplyDelete
  5. why I can't paste code, in add source directly? please help me...

    ReplyDelete
  6. How can i save image by long press please..

    ReplyDelete
  7. How to read and download PDF file from webpage on Sketchware. Pls help out.

    ReplyDelete
    Replies
    1. Try putting this code in onCreate

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

      Delete
  8. How can I add pdf files in my app made by sketchware

    ReplyDelete
  9. I can still inject code in the latest version.The block is in the operator section

    ReplyDelete
  10. How to download an image using 'set image from url' block ?

    ReplyDelete
  11. I am impressed by the above info I found here. This is really a great news. I myself love such kind of news.
    Ielts Sample Test |
    Ielts Practice Test |
    Ielts practice test online |
    Ielts mock test |
    Ielts general practice test |

    ReplyDelete
  12. The 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...
    Ielts reading practice test |
    Ielts reading practice |
    Ielts general reading practice test |

    ReplyDelete
  13. 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.
    Ielts listening practice test |
    Ielts listening practice |

    ReplyDelete
  14. 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.
    Ielts 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 |

    ReplyDelete
  15. 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.
    Ielts speaking topics |
    Ielts speaking questions |
    Ielts speaking sample |
    Ielts speaking tips |

    ReplyDelete
  16. 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.
    Office Administration Course |
    Office Administration Certificate |
    Office Admin Course |

    ReplyDelete
  17. 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!
    Food Handlers Certificate |
    Food Handling Course |

    ReplyDelete
  18. 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.
    IELTS 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 |

    ReplyDelete
  19. It's showing no permission to write to sdcard. But I have given storage permission.

    ReplyDelete
  20. Can I download Facebook video with this

    ReplyDelete

Post a Comment

Popular posts from this blog

Create Music Player app in Sketchware

A Flash Light App in Sketchware

Admob rewarded video Ads in Sketchware

Simple car racing android game in Sketchware

Firebase auth in Sketchware for Login Activity