Android_自定义url路径web端打开App

Web界面代码

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Insert title here</title>

    </head>

    <body>

        <a href="liyue://888.com/">打开app</a><br/>

    </body>

</html>

看Android端配置文件代码

  <!--过渡界面-->
        <activity
            android:name=".guidemodule.activity.SplashActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
                    <!--这里一定要写两个过滤器,不然你的app图标就会找不到-->
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="888.com"
                    android:scheme="liyue" />
            </intent-filter>
        </activity>

好了,通过上边的方式就可以打开自己App了.

如何获取web链接传递过来的参数呢

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Insert title here</title>
    </head>
    <body>
        <a href="liyue://888.com/?arg=0&data=1">打开app</a><br/>
    </body>
</html>

如果你是通过webchrome打开的

Uri uri = getIntent().getData();  
String test1= uri.getQueryParameter("arg");  
String test2= uri.getQueryParameter("data");

如果你是webview打开的

webView.setWebViewClient(new WebViewClient(){
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
      Uri uri=Uri.parse(url);
          if(uri.getScheme().equals("liyue")&&uri.getHost().equals("888.com)){
              String arg0=uri.getQueryParameter("arg");
              String arg1=uri.getQueryParameter("data");

          }else{
              view.loadUrl(url);
          }
      return true;
  }
});

有什么不懂得欢迎留言给我,或者加我个人微信公众号
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值