0

I have to load these Url by using the below code.But finally blank screen displayed as a output.you can check theurl link between code at the last line.

WebPagerLoader.java:

public class WebPageLoader extends Activity
{

final Activity activity = this;
private String html;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.activity_main);
        WebView webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);

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

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {

            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }
        });

  webView.loadUrl("<iframe src=\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045\" width=\"640\" height=\"385\" seamless=\"seamless\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\"></iframe>";
    }
}       

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.webpageloader"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.webpageloader.WebPageLoader"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

finally I get a blank screen.I doesn't know what I did wrong in webView.loadUrl. I doesn't know how to solve these.Anybody can help me with these problem.Thank You.

2
  • Try using str = http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045%22%20width=%22640%22%20height=%22385%22%20seamless=%22seamless%22%20scrolling=%22no%22%20frameborder=%220%22%20allowtransparency=%22true%22 webView.loadDataWithBaseURL(null, str, "text/html", "UTF-8", null);
    – Aniruddha
    Jun 9, 2014 at 10:23
  • @Aniruddha your previous comment help me to solve these problem.post your answer like these: webView.loadDataWithBaseURL(null, "<iframe src=\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045\" width=\"640\" height=\"385\" seamless=\"seamless\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\"></iframe>", "text/html", "UTF-8", null);. then if you provide some explanation with that answer also its better for me.
    – Stephen
    Jun 9, 2014 at 10:38

2 Answers 2

5

Change your

webView.loadUrl("<iframe src=\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045\" width=\"640\" height=\"385\" seamless=\"seamless\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\"></iframe>";

to

webView.loadDataWithBaseURL(null, "<iframe src=\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bg‌​color=EEEEEE&t=1381431045\" width=\"640\" height=\"385\" seamless=\"seamless\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\"></iframe>", "text/html", "UTF-8", null);

The loadDataWithBaseURL() method takes, among other parameters, the “base URL” to use when resolving relative URLs in the HTML. Any relative URL (e.g., ) will be interpreted as being relative to the base URL supplied to loadDataWithBaseURL(). If you find that you have content that refuses to load properly with loadData(), try loadDataWithBaseURL() with a null base URL, as sometimes that works better, for unknown reasons.

1
  • > as sometimes that works better, for unknown reasons. If you don't specify base url, the entire text becomes your url. And if that text contains # character, it the is interpreted as anchor and eveything after the # character gets cut off. Probably similar bug exists for other characters too
    – Alexey
    Aug 23, 2019 at 7:13
1

i have tried and works fine in webviewFragment

 public class WebPageLoader extends Activity
 {

   final Activity activity = this;
   private String html;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
      super.onCreate(savedInstanceState);
      this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
      setContentView(R.layout.activity_main);
      WebView webView = (WebView) findViewById(R.id.webview);
      webView.getSettings().setJavaScriptEnabled(true);

webview.loadUrl("http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045");

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

     webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
        {

        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            view.loadUrl(url);
            return true;
        }
    });

 }
}       
  • its too much memory consuming file so may its no see proper or blank screen but its work fine but not same as web browser
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.