17

I'm already active JavaScript for a given WebView, and opens new link inside the WebView, not in the Browser. This Is Main Activity

 package com.Afrogfx.pronouns; import android.os.Bundle; import android.annotation.SuppressLint; import android.app.Activity; import android.view.Menu; import android.webkit.WebView; @SuppressLint("SetJavaScriptEnabled") public class MainActivityPronouns extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_activity_pronouns); WebView wvHtml = (WebView) findViewById(R.id.webview); wvHtml.getSettings().setBuiltInZoomControls(true); wvHtml.getSettings().setJavaScriptEnabled(true); wvHtml.loadUrl("http://afrogfx.com/appcatcategories.php?catid=13&parentid=11"); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main_activity_pronouns, menu); return true; } } 

how can i handel my code to open all link in site inside the WebView (App) , not in the Browser & ( don't show to user Open in browser).

1

3 Answers 3

32

For that just create the subclass that is extending webclient and use the method of that class onPageFinished(WebView c,String url) and
public boolean shouldOverrideUrlLoading(final WebView view, final String url)

here is the code-

 myWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { //view.loadUrl(url); System.out.println("hello"); return false; } }); myWebView.loadUrl(url); 
Sign up to request clarification or add additional context in comments.

2 Comments

The docs say you should return false to continue loading that url. returning true will abort loading
I agree with @henon, it should be false
13

In case you use Kotlin:

webView.webViewClient = object : WebViewClient() { override fun shouldOverrideUrlLoading( view: WebView?, request: WebResourceRequest? ): Boolean { return false } } 

Comments

-2

so you have to use WebviewClicent .. here is the class

private class HelloWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(final WebView view, final String url) { Utils.showActivityViewer(WebsiteActivity.this); new Thread(new Runnable() { public void run() { view.loadUrl(url); } }).start(); return true; } } 

and bind in a webview as

webview.setWebViewClient(new HelloWebViewClient()); 

and refer http://developer.android.com/reference/android/webkit/WebViewClient.html

1 Comment

Welcome to "Only the original thread that created a view hierarchy can touch its views.” exception )

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.