1

I have a simple webview app that stats with a splash screen. As it goes to the MainActivity it will open in Chrome but only while on mobile data. If on wifi it opens in the app. Opening in the app is the intended action. How can I force the page to open in my webview regardless of connection type? See my code below...

Note: links clicked within the webview open in Chrome, which is the intended action.

I hope I was clear enough, I've only been developing apps for a month or so. Thanks! I really appreciate the help!

public class MainActivity extends AppCompatActivity implements AdvancedWebView.Listener {

  private AdvancedWebView mWebView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebView = (AdvancedWebView) findViewById(R.id.webview);
    mWebView.setListener(this, this);
    mWebView.loadUrl("http://seanpattersondesigns.com");
    boolean preventCaching = false;
    mWebView.setGeolocationEnabled(true);
    mWebView.loadUrl("http://seanpattersondesigns.com", preventCaching);
    mWebView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url != null && url.startsWith("http://")) {
                view.getContext().startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                return true;
            } else {
                return false;
            }
        }
    });
  }

  @SuppressLint("NewApi")
  @Override
  protected void onResume() {
    super.onResume();
    mWebView.onResume();
  }

  @SuppressLint("NewApi")
  @Override
  protected void onPause() {
    mWebView.onPause();

    super.onPause();
  }

  @Override
  protected void onDestroy() {
    mWebView.onDestroy();

    super.onDestroy();
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    mWebView.onActivityResult(requestCode, resultCode, intent);

  }

  @Override
  public void onBackPressed() {
    if (mWebView.canGoBack()) {
        mWebView.goBack();
    } else {
        finish();
    }
  }

  @Override
  public void onPageStarted(String url, Bitmap favicon) {
  }

  @Override
  public void onPageFinished(String url) {
  }

  @Override
  public void onPageError(int errorCode, String description, String failingUrl) {
  }

  @Override
  public void onDownloadRequested(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {

  }

  @Override
  public void onExternalPageRequest(String url) {
  }

}
pretz
  • 232
  • 2
  • 14
  • Possible duplicate of [Android webview launches browser when calling loadurl](http://stackoverflow.com/questions/7746409/android-webview-launches-browser-when-calling-loadurl) – buczek Apr 14 '16 at 20:52
  • Thanks for the reply buczek. Though my issue is the different behavior when not connected to WiFi and using mobile data. I wasn't sure if there was another permission I needed to add to my manifest? – pretz Apr 14 '16 at 21:32
  • Did you try moving your setWebViewClient before calling loadURL? I had a similar issue and that was the resolution for me. – buczek Apr 14 '16 at 21:34
  • I tried and no luck. I'm trying it in different places hoping I hit the right spot. Not the best method, but I don't really know what else to do. – pretz Apr 14 '16 at 23:34
  • Did you also try on different devices? – buczek Apr 15 '16 at 16:09
  • I'm not sure what was going on. I stripped my code and started over and the issue is fixed. – pretz Apr 20 '16 at 16:56

0 Answers0