Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,160,415 members, 7,843,233 topics. Date: Tuesday, 28 May 2024 at 09:16 PM

Android Webview - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Android Webview (1138 Views)

Embed And Play Youtube Video In Android Webview (2) (3) (4)

(1) (Reply)

Android Webview by Xcetera(m): 4:31pm On Jul 25, 2015
Hello Android Developers,

Please I have an Issue here wouldn't know if it's small or big.... smiley.
I'm implementing export to PDF in an android app (Someone has already work on a part that loads the content into the webview), the concept I'm using is to convert the content of the webview to an image then attach that image to a PDF file.

The challenge now is that, the image is always empty because the url that's being loaded is via loadBaseURL. However if I do loadURL and parse a url e.g https://www.google.com, once the URL has been successfully loaded, the image is created with the landing page of google.

So I don't know if anyone have an idea of what I'm doing wrong that when using loadBaseURL the image is always white.

Below is the part where I'm trying to capture the content of the webview:

webView.loadDataWithBaseURL("file:///android_asset/", (htmlString + htmlBody), "text/html", "utf8", null);
//webView.loadUrl("http://");
//==========================Export to PDF==========================
webView.setWebViewClient(new WebViewClient() {

@Override
public void onPageFinished(WebView view, String url) {

//Picture webViewShot = view.capturePicture();
webView.setDrawingCacheEnabled(true);
webView.buildDrawingCache();


Bitmap bmp = Bitmap.createBitmap(webView.getWidth(), webView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
//Paint paint = new Paint();
//canvas.drawBitmap(bmp, 0, bmp.getHeight(), paint);
webView.draw(canvas);
System.out.println("Inside onPageFinished" + canvas.getWidth() + " " + canvas.getHeight());
//webView.draw( canvas );

FileOutputStream out = null;
try {
out = new FileOutputStream(IMAGE_FILE);
//out.write(IMAGE_FILE.toString().getBytes());
} catch (FileNotFoundException e) {

e.printStackTrace();
}
bmp.compress(Bitmap.CompressFormat.JPEG, 97, out);
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}

Your kind assistance would be highly appreciated.

Looking forward to your responses.

Thank you very much.

(1) (Reply)

Spectranet For Linux / Developing An Idea Into An Application / ......

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.