I have a webview in my xml which goes like below:
<WebView
android:id="@+id/webView"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
I am loading the webview like this:
String webView_text = "Lorem ipsum..............**<a><u>Link to fire intent</u></a>**";
WebView webView= (WebView) findViewById(R.id.webView);
webView.loadData(String.format(htmlText, webView_text), "text/html", "utf-8");
webView.setWebViewClient(new WebViewClient()
{
// Override URL
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Intent intent = new Intent(getApplicationContext(),OtherActivity.class);
startActivity(intent);
return true;
}
});
Please notice that I am creating the link in my string (webView_text) by using the html tag and overriding the function to fire an intent. It is not doing in this case. What is the problem here? I am not sure if Android Webview supports the tag (I believe it should). What is my mistake here.Thanks in advance.
We can use webview same as textview also.
I hope this may help others.Thanks!
I think it's because the anchor tag doesn't have an href attribute.
you can this by define scheme in activity intent filter in manifest. for sample create activity (A) and activity (B) and define in manifest like this :
if in your html have linke like this:
when you click it , start activity B. Activity A is similar to it.
you can get source code from Source Code
NOTE : if using webview for this method you must override the method
shouldOverrideUrlLoading()
and compare the every url.