当前位置: 移动技术网 > IT编程>移动开发>Android > android Activity Scheme跳转协议运用讲解

android Activity Scheme跳转协议运用讲解

2018年11月01日  | 移动技术网IT编程  | 我要评论

天府情话,toto智能马桶盖价格,暴风凛冽的夜晚

scheme协议

android中的scheme是一种页面内跳转协议,通过自定义scheme协议,可以跳转到app中的任何页面。

服务器可以定制化跳转app页面app可以通过scheme跳转到另一个app页面可以通过h5页面跳转app原生页面

协议格式

 uri.parse("qh://test:8080/goodsgoodsid=8897&name=fuck")

qh代表scheme协议名称test代表scheme作用的地址域8080代表改路径的端口号/goods代表的是指定页面(路径)goodsid和name代表传递的两个参数

scheme使用

定义一个scheme

 
            
            
                 
                
                
                
                
                
            
        

获取scheme跳转的参数

uri uri = getintent().getdata();
        if (uri != null) {
            // 完整的url信息
            string s = uri.tostring();
            sb.append(s + "\n");
            // scheme部分
            string scheme = uri.getscheme();
            sb.append("scheme=" + scheme + "\n");
            // host部分
            string host = uri.gethost();
            sb.append("host=" + host + "\n");
            // 访问路劲
            string path = uri.getpath();
            sb.append("path=" + path + "\n");
            //port部分
            int port = uri.getport();
            sb.append("port=" + port + "\n");
            // query部分
            string query = uri.getquery();
            sb.append("query=" + query + "\n");
            //获取指定参数值
            string goodsid = uri.getqueryparameter("goodsid");
            sb.append("goodsid=" + goodsid + "\n");
            //列举所以参数名
            set queryparameternames = uri.getqueryparameternames();
            tv_scheme.settext(sb.tostring());
        }

调用方式

 1. 原生调用
 intent intent1 = new intent(intent.action_view, uri.parse("qh://test:8080/goodsgoodsid=8897&name=fuck"));
                startactivity(intent1);
2. html调用
<a href="qh://test:8080/goods?goodsid=8897&name=fuck">打开商品详情</a>

判断某个scheme是否有效

intent intent = new intent(intent.action_view, uri.parse("qh://test:8080/goodsgoodsid=8897&name=fuck"));
list activities = getpackagemanager().queryintentactivities(intent, 0);
boolean isvalid = !activities.isempty();
if (isvalid) {
    startactivity(intent);
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网