您的位置:首页 > 移动开发

WebView 总结

2013-12-03 00:00 302 查看
1.每次跳转只存在一个webActivity webView.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // TODO Auto-generated method stub view.loadUrl(url); return true; } }); AndroidManifest中如下设置 2.web加载前添加事件和加载后去掉事件 。获取web的url。 public class WebPayActivity extends Activity { private String userId; private String serverId; private String payResultUrl; private ProgressBar bar; private String str; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.payweb); Intent intent = getIntent(); Bundle bundle = intent.getExtras(); userId = bundle.getString("USERID"); serverId = bundle.getString("SERVERID"); viewLoad(); } private void viewLoad() { String url = Constant.TestPayUrl; String gopc_serviceappid = Constant.Gopc_ServiceAppId; String gopc_servicekey = Constant.gopc_ServiceKey; String gopc_transdate = Util.getDate(); String orderId = serverId + userId + gopc_transdate; String gopc_transid = orderId; String gopc_pamentttype = ""; int gopc_agencyid = Integer.parseInt(Constant.Agencyid); Long gopc_accountid = Long.parseLong(userId); LoveDanceActivity lda = new LoveDanceActivity(); String gopc_returnurl = lda.billUrl; int num1 = gopc_returnurl.lastIndexOf("/"); int num2 = gopc_returnurl.lastIndexOf(":"); String gopc_accountip = gopc_returnurl.substring(num1 + 1, num2); payResultUrl = gopc_returnurl; String sha_input = Constant.Secure_Secret + gopc_accountid + gopc_accountip + gopc_agencyid + gopc_pamentttype + gopc_returnurl + gopc_serviceappid + gopc_servicekey + gopc_transdate + gopc_transid; String gopc_securehash = Util.getMD5(sha_input).toUpperCase(); String body = "gopc_accountid=" + gopc_accountid + "&gopc_accountip=" + gopc_accountip + "&gopc_agencyid=" + gopc_agencyid + "&gopc_pamentttype=" + gopc_pamentttype + "&gopc_returnurl=" + gopc_returnurl + "&gopc_serviceappid=" + gopc_serviceappid + "&gopc_servicekey=" + gopc_servicekey + "&gopc_transdate=" + gopc_transdate + "&gopc_transid=" + gopc_transid + "&gopc_securehash=" + gopc_securehash; url += body; str = url; initWebView(url); } private int getOrderId() { int cooOrderSerial = 0; return cooOrderSerial; } private void initWebView(String url) { WebView authorizationView = (WebView) findViewById(R.id.web_view); bar = (ProgressBar) findViewById(R.id.progressBar1); setProgress(bar); authorizationView.clearCache(true); authorizationView.getSettings().setJavaScriptEnabled(true); authorizationView.getSettings().setSupportZoom(true); authorizationView.getSettings().setBuiltInZoomControls(true); authorizationView.setWebViewClient(new WebViewC()); authorizationView.loadUrl(url); } private void setProgress( final ProgressBar bar) { bar.setMax(100); new Thread() { public void run() { for (int i = 0; i < 100; i++) { try { bar.setProgress(i); Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; }.start(); } class WebViewC extends WebViewClient { private int index = 0; @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); if (url.startsWith(payResultUrl)) { finish(); } } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (url.equals(str)) { bar.setVisibility(8); } } } }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息