1

Below I attached the code to be executed with webview.

NOTE: JAVASCRIPT SHOULD BE ENABLED

ANYONE HELP ME TO RUN THIS HTML STRING IN WEBVIEW

<!DOCTYPE html>
<html>
<body>
<!-- Markup for HTML (Factors in Placement and Enrollment of Primary 
Care Patientsin YMCA&#39;s Diabetes Prevention Program, Bronx, New 
York,2010-2015) --><div class='rid_08184eef_309335' 
data-apiroot='//tools.cdc.gov/api' data-mediatype='html' 
data-mediaid='309335' data-stripscripts='true' data-stripanchors='false' 
data-stripimages='false' data-stripcomments='true' 
data-stripstyles='true' data-cssclasses='syndicate' data-ids='' 
data-xpath='' data-oe='utf-8' data-of='xhtml' data-ns='cdc' 
data-postprocess='' data-nw='true' data-iframe='true' 
data-cdc-widget='syndicationIframe' 
data-apiembedsrc='skins/larry//tools.cdc.gov/api/embed/html/js/embed-2.0.3.js' 
data-iframeembedsrc='skins/larry//tools.cdc.gov/TemplatePackage/contrib/widgets/tp-widget-external-loader.js'></div><script 
src='skins/larry//tools.cdc.gov/TemplatePackage/contrib/widgets/tp-widget-external-loader.js' 
 ></script><noscript>You need javascript enabled to view this content or go to <a href='skins/larry//tools.cdc.gov/api/v2/resources/media/309335/noscript'>source URL</a>.</noscript>

</body>
</html>

I followed this link for basic setup. Nothing helped

BELOW I ATTACHED MY JAVA CODE

public class WebtestActivity extends Activity {
WebView webtest;
final Activity activity = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.webviewtesting);
    webtest=(WebView)findViewById(R.id.webtest);
    String htmlString = "<!-- Markup for HTML (How to Prevent Cancer or Find It Early) --><div class=\"rid_ec9fb40c_123238\" data-apiroot=\"//tools.cdc.gov/api\" data-mediatype=\"HTML\" data-mediaid=\"123238\" data-stripscripts=\"false\" data-stripanchors=\"false\" data-stripimages=\"false\" data-stripcomments=\"false\" data-stripstyles=\"false\" data-cssclasses=\"syndicate\" data-ids=\"\" data-xpath=\"\" data-oe=\"UTF-8\" data-of=\"XHTML\" data-ns=\"\" data-postprocess=\"\" data-nw=\"true\" data-iframe=\"true\" data-cdc-widget=\"syndicationIframe\" data-apiembedsrc=\"//tools.cdc.gov/api/embed/html/js/embed-2.0.3.js\" data-iframeembedsrc=\"//tools.cdc.gov/TemplatePackage/contrib/widgets/tp-widget-external-loader.js\" data-font=\"\"></div><script src='//tools.cdc.gov/TemplatePackage/contrib/widgets/tp-widget-external-loader.js' ></script><noscript>You need javascript enabled to view this content or go to <a href='//tools.cdc.gov/api/v2/resources/media/123238/noscript'>source URL</a>.</noscript>";
    webtest.getSettings().setJavaScriptEnabled(true);

    webtest.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress)
        {
            activity.setTitle("Loading...");
            activity.setProgress(progress * 100);

            if(progress == 100)
                activity.setTitle(R.string.app_name);
        }
    });

    webtest.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
        {
            // Handle the error
            Log.d("des===",description);
            Log.d("failingUrl===",failingUrl);

        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            Log.d("shouldlLoading===",url);
            view.loadUrl(url);
            return true;
        }
    });

    webtest.loadData(htmlString, "text/html", null);

}

} enter image description here

1

1 Answer 1

4

try this code. If you are learning, use official docs > WebView

String htmlString = "<html><body>Your text.</body></html>";
browser.getSettings().setJavaScriptEnabled(true);
browser.loadData(htmlString, "text/html", null);

Your code working fine. I attached screenshot

enter image description here

Sign up to request clarification or add additional context in comments.

9 Comments

Can u try the above html with your mentioned code? I tried the same with device but nt working
Yes, I tried. works fine. you can use WebChromeClient instead of WebViewClient. Try it . and where is your Java code?
Can u check the code and run the same with your side. If it shows html page kindly share screenshot with me, so that i can come to know where the prblm occurs
Yes, I checked, it works. I attached a screenshot from above
A normal HTML file is woking to me also, but the above-mentioned HTML Tags works only if running with the server . For that only I asked you to try the mentioned HTML code
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.