0

im trying to make app based on WebView of mobile page. The thing is that page loads in default user's browser instead of app. Here is my code, any thoughts about what am i doing wrong?

package pl.beat_down.bdmobile;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.app.Activity;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url = "http://beat-down.pl/m";
WebView view = (WebView) this.findViewById(R.id.webView1);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(url);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) { 
int id = item.getItemId();

if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}    
Restu
  • 37
  • 1
  • 6
  • probably there´s one or more redirections, follow this guys sample and you will get it to work: http://stackoverflow.com/questions/4066438/android-webview-how-to-handle-redirects-in-app-instead-of-opening-a-browser – eduyayo Aug 04 '15 at 11:48
  • instead of this `WebView view = (WebView) this.findViewById(R.id.webView1);` try `WebView view = (WebView) findViewById(R.id.webView1);` – karan Aug 04 '15 at 11:49

1 Answers1

0

You need to set WebViewClient in WebView like they said in documentation.

Just implement the web client and set it before loadUrl. Like this-

webview.setWebViewClient(new WebViewClient());
Hein
  • 2,675
  • 22
  • 32
  • Hi there, i dont know why but im getting 2 errors Error:(15, 38) error: cannot find symbol class WebViewClient Error:(15, 16) error: non-static method setWebViewClient(WebViewClient) cannot be referenced from a static context – Restu Aug 04 '15 at 11:59