0

When I click on the link, the Facebook website has a notification at the top that say "Download our app". I want to be able to remove that. Here is my WebView Activity:

public class FacebookActivity extends AppCompatActivity {

WebView webView;
String url = "https://www.facebook.com";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_facebook);

    webView = (WebView)findViewById(R.id.facebookWebView);
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
        webView.goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

}

Also I am just starting to learn Android development so if you see any mistakes, or easier ways to do this, that would be really helpful.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

You can do this by making a custom WebViewClient (basically a class that extends WebViewClient and can override its methods). The method you want to override is onPageFinished(). You can then inject custom js inside this method call on the page to do what you wish to the content.

these links should help:

https://developer.android.com/guide/webapps/managing-webview#programmatic-actions

This SO question is similar:

Any way to hide elements from webview? (android)

and this reddit post might help too:

https://www.reddit.com/r/learnprogramming/comments/16yqhm/remove_html_elements_from_an_android_webview/

As mentioned in the above posts: make sure you get your html/js code right. A semicolon miss here or there wont lead to the effect you are expecting.

shiredude95
  • 560
  • 3
  • 7