为各种结构化网址启用Android的深层链接

时间:2015-06-24 05:35:25

标签: android webview

我已启用深层链接&它从网址打开应用程序。但是它仅打开主要网址,即m.example.com&不是m.example.com\products\iphone-5s\

我正在使用WebView将我的移动网站加载到Android应用中。

这是xml文件的代码:

<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="m.example.com"
        android:pathPrefix="/"
        android:scheme="http" />
</intent-filer>

Java文件:

private String url='m.example.com';

@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    String action = intent.getAction();
    Uri data = intent.getData();
    mainWebView.loadUrl(url);
}

有人可以帮忙解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

Uri data = intent.getData();

之后立即获取包含此代码的网址链接
String link = intent.getDataString();

然后,设置简单的if / else

    if (link == null) {
        mWebView.loadUrl("yourMainURL");
    } else {
        mWebView.loadUrl(link);
    }
相关问题