您好,欢迎来到钮旅网。
搜索
您的当前位置:首页Android_自定义url路径web端打开App

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;
  }
});

有什么不懂得欢迎留言给我,或者加我个人微信公众号

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- niushuan.com 版权所有 赣ICP备2024042780号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务