I know that many of you know this already but I am making a post because I spent 5 hours trying to figure out why loadData was not working. This does not pop up easily in searches of the mailing list.
TAGS: webview background white android loadData WebView momentContent = (WebView) view.findViewById (R.id.subscription_list_moment_webcontent); WebSettings wsettings = momentContent.getSettings(); wsettings.setJavaScriptEnabled(true); //works great //momentContent.loadUrl("http://www.momentarynow.com/app/public/ android/info_about.html"); //doesnt work exact same content WHY? momentContent.loadData( ResourceUtils.loadResToString(R.raw.content, mContext), mimeType, encoding); ==== <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <style type="text/css"> <!-- .bg { font-size: x-small; background-color: #CC6600; } --> </style> </head> <body class="bg"> foobar </body> </html> unless you use the most simple html possible, like no style sheets, backgrounds, etc, loadData seems to blow up. The only workaround I have found is to use loadDataWithBaseURL instead final String mimeType = "text/html"; final String encoding = "UTF-8"; //render the html WebView momentContent = (WebView) findViewById(R.id.subscription_list_moment_webcontent); WebSettings wsettings = momentContent.getSettings(); wsettings.setJavaScriptEnabled(true); momentContent.loadDataWithBaseURL("http://fake.com", ResourceUtils.loadResToString( R.raw.content, getApplicationContext()), mimeType, encoding, "http://fake.com"); oh now it magically works. but my forehead is a bit bruised from hammering it against the brick wall. I merely post to help others avoid my fate. Clay --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---