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

Web界面代码

<html>

    <head>

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

        <title>Insert title heretitle>

    head>

    <body>

        <a href="liyue://888.com/">打开appa><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>
                    
            <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 heretitle>
    head>
    <body>
        <a href="liyue://888.com/?arg=0&data=1">打开appa><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;
  }
});

有什么不懂得欢迎留言给我,或者加我个人微信公众号
Android_自定义url路径web端打开App_第1张图片

你可能感兴趣的:(android,web,url,uri,Android默认机制)