Thread Rating:
  • 0 Vote(s) - 0 Average
Webview app test
#1
MainActivity.java:

Code:
public class WebActivity extends Activity {
 WebView wv;

String url="http://www.teluguoneradio.com/rssHostDescr.php?hostId=147";

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_web);
   wv=(WebView)findViewById(R.id.webUrl_WEB);



WebSettings webSettings = wv.getSettings();
   wv.getSettings().setLoadWithOverviewMode(true);
   wv.getSettings().setUseWideViewPort(true);
   wv.getSettings().setBuiltInZoomControls(true);
   wv.getSettings().setPluginState(PluginState.ON);


   wv.setWebViewClient(new myWebClient());

   wv.loadUrl(url);
}




public class myWebClient extends WebViewClient {
   @Override
   public void onPageStarted(WebView view, String url, Bitmap favicon) {
       // TODO Auto-generated method stub
       super.onPageStarted(view, url, favicon);
   }

   @Override
   public boolean shouldOverrideUrlLoading(WebView view, String url) {
       // TODO Auto-generated method stub

       view.loadUrl(url);
       return true;

   }
}
ADD:
Code:
[code]@Override
   public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
   final AlertDialog.Builder builder = new AlertDialog.Builder(this);
   String message = "SSL Certificate error.";
       switch (error.getPrimaryError()) {
           case SslError.SSL_UNTRUSTED:
               message = "The certificate authority is not trusted.";
               break;
           case SslError.SSL_EXPIRED:
               message = "The certificate has expired.";
               break;
           case SslError.SSL_IDMISMATCH:
               message = "The certificate Hostname mismatch.";
               break;
           case SslError.SSL_NOTYETVALID:
               message = "The certificate is not yet valid.";
               break;
       }
       message += " Do you want to continue anyway?";

       builder.setTitle("SSL Certificate Error");
       builder.setMessage(message);
   builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
       @Override
       public void onClick(DialogInterface dialog, int which) {
           handler.proceed();
       }
   });
   builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
       @Override
       public void onClick(DialogInterface dialog, int which) {
           handler.cancel();
       }
   });
   final AlertDialog dialog = builder.create();
   dialog.show();

[/code]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)