Yusuf Ali
Yusuf Ali

Reputation: 173

WebView opens default browser when application starting

My problem isn't when i click the link. It goes when application starting.

protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.browser);

        WebView wvBrowser = (WebView) findViewById(R.id.wvBrowser);
        wvBrowser.loadUrl("http://yusufalibozkir.com");
    }

And, xml:

<WebView 
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:id="@+id/wvBrowser"
        />

Upvotes: 0

Views: 147

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006554

http://yusufalibozkir.com issues an HTTP 301 redirect response. WebView treats redirects in the same way it treats link clicks, by opening the default Web browser. Use a WebViewClient and shouldOverrideUrlLoading() to catch this occurrence and load the resulting URL back in the WebView, or use a URL that does not issue a redirect in the first place.

Upvotes: 1

Related Questions