Issue
I have a Webiew
. I want read clicked link's url but Webiew
mustn't go this url. WebView must stay same page.
Example: User clicks "https://stackoverflow.com/questions" button and app read this link. But WebView must still stay on "https://stackoverflow.com/" without refresh. I can read clicked link's URL but i can't stop the WebView, it goes to new url.
Solution
As @Sudheesh suggest you should extend WebView
provide an new implementation of shouldOverrideUrlLoading.
Is the same case of Web View onclick event for a specific link in that webview .
I think you should avoid to call super.shouldOverrideUrlLoading(view, url);
to prevent the default behaviour.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wv = (WebView) findViewById(R.id.myWebView);
wv.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(isURLMatching(url)) {
openNextActivity();
return true;
}
//return super.shouldOverrideUrlLoading(view, url);
return false;
}
});
}
protected boolean isURLMatching(String url) {
// some logic to match the URL would be safe to have here
return true;
}
protected void openNextActivity() {
Intent intent = new Intent(this, MyNextActivity.class);
startActivity(intent);
}
Answered By - Panciz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.