• Android WebView 拦截自定义协议


    URL 语法

    URL由三部分组成:资源类型、存放资源的主机域名、资源文件名。
    
    
    URL的一般语法格式为:
    
    
    (带方括号[]的为可选项):
    
    
    protocol :// hostname[:port] / path / [;parameters][?query]#fragment 

    1 public static class CommonWebViewClient extends WebViewClient { 2 3 @Override 4 public boolean shouldOverrideUrlLoading(WebView view, String url) { 5 Log.d("leo", "[webViewUrl]" + url); 6 if (url.startsWith("tel")) {// 机构电话 7 Intent intent = new Intent(Intent.ACTION_DIAL); 8 intent.setData(Uri.parse(url)); 9 view.getContext().startActivity(intent); 10 return true; 11 } 12 Uri uri = Uri.parse(url); 13 if ("baonajia".equals(uri.getScheme())) { 14 if ("organization".equals(uri.getHost())) {// 课程详情跳转到机构详情 15 Organization organization = new Organization(); 16 organization.setId(uri.getQueryParameter("organization_id")); 17 organization.setName(uri.getQueryParameter("organization_name")); 18 Intent intent = new Intent(view.getContext(), OrganizationDetailActivity.class); 19 intent.putExtra(Const.EXTRA_ORG, organization); 20 view.getContext().startActivity(intent); 21 } else if ("course".equals(uri.getHost())) {// 机构详情跳转到课程详情 22 new CourseTask(view, uri.getQueryParameter("course_id")).execute(); 23 } else if ("school".equals(uri.getHost())) {// 机构详情跳转到校区列表 24 String orgId = uri.getQueryParameter("organization_id"); 25 Intent intent = new Intent(view.getContext(), SchoolListActivity.class); 26 intent.putExtra(Const.EXTRA_ORG_ID, orgId); 27 view.getContext().startActivity(intent); 28 } else if ("album".equals(uri.getHost())) {// 机构详情跳转到相册列表 29 String orgId = uri.getQueryParameter("organization_id"); 30 Intent intent = new Intent(view.getContext(), PhotoAlbumListActivity.class); 31 intent.putExtra(Const.EXTRA_ORG_ID, orgId); 32 view.getContext().startActivity(intent); 33 } 34 35 return true; 36 } else { 37 view.loadUrl(url); 38 return true; 39 } 40 } 41 42 @Override 43 public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 44 Log.e(TAG, 45 String.format("errorCode: %s, description: %s, when open: %s", errorCode, description, failingUrl)); 46 view.loadUrl(URLCenter.getError()); 47 } 48 }
  • 相关阅读:
    P4213【模板】杜教筛
    【SDOI2006】线性方程组
    【AHOI2018】排列
    【NOI2001】炮兵阵地
    【NOIP2012】疫情控制
    【AHKOI2017】rexp
    【十二省联考2019】春节十二响
    【TJOI2014】匹配
    【AT2645】Exhausted?
    P3809 【模板】后缀排序
  • 原文地址:https://www.cnblogs.com/jinglecode/p/5584400.html
Copyright © 2020-2023  润新知