Ma vue Web ne fonctionne pas pour les URL qui redirigent vers une autre page. Il ouvre les navigateurs à partir de l'application mais ne charge pas la vue Web. Une idée?
Le code pour webview est:
webView = (WebView) findViewById(R.id.simpleWebView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
if(getIntent().getStringExtra("url")!=null){
loadLink(getIntent().getStringExtra("url"));
}else{
Toast.makeText(WebViewActivity.this, "Please try again later!",
Toast.LENGTH_SHORT).show();
finish();
}
Classe principale
public class Main extends Activity {
private WebView webview;
private static final String TAG = "Main";
private ProgressDialog progressBar;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
this.webview = (WebView)findViewById(R.id.webview);
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
progressBar = ProgressDialog.show(Main.this, "WebView Example", "Loading...");
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i(TAG, "Processing webview url click...");
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
Log.i(TAG, "Finished loading URL: " +url);
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.e(TAG, "Error: " + description);
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
alertDialog.setTitle("Error");
alertDialog.setMessage(description);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
});
webview.loadUrl("http://www.google.com");
}
}
Votre mise en page main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:orientation="vertical"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
>
<WebView Android:id="@string/webview"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
Android:layout_weight="1" />
</LinearLayout>
Essayez de remplacer la méthode du client Web-view cela vous aidera
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Here put your code
Log.d("My Webview", url);
// return true; //Indicates WebView to NOT load the url;
return false; //Allow WebView to load url
}
});
Je pense que vous devriez écrire ce que contient votre méthode loadLink. Êtes-vous sûr de l'avoir correctement implémentée - webView.loadUrl (...)?
webView=(WebView)view.findViewById(R.id.webview);
webView.setWebViewClient(new MyBrowser());
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadUrl("https://www.google.co.in/");
return view;
}
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
pDialog.dismiss();
}
}