我正在开发一个项目,我有一个Javascript页面,我在其中制作Canvas并将此画布下载为PNG图像。
它在网络浏览器和移动浏览器上运行良好。
但是,我想在我的Android App上的WebView中显示这个Js页面。问题是下载不适用于webview。
我已经尝试了很多不同的选项,例如Download Manager和Download Listnner。
我希望我的应用能够在App的WebView上将画布作为PNG下载。
希望有人帮忙!谢谢! ;)
MY Js Canvas Code:
function downloadCanvas(link, canvasId, filename) {
link.href = document.getElementById(canvasId).toDataURL('image/png');
link.download = filename;}
document.getElementById('btn-download').addEventListener('click', function() {
downloadCanvas(this, 'canvas', "myCanvasImage.png");
}, false);
这是我的Adroid代码:
WebView mapview1 = (WebView) findViewById(R.id.map_view1);
mapview1.loadUrl("http://www.myjscanvas.com/download");
WebSettings webSettings = mapview1.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.getAllowFileAccessFromFileURLs ();
mapview1.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});