深入链接webview中的正确页面

我为我们的网站做了一个android webview应用程序。 现在,我想添加深层链接到应用程序,就像有人点击我们网站的链接时,您可以使用webview应用程序而不是Chrome浏览器打开它。 我将这些添加到我的清单中:

<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:scheme="https" android:host="www.example.com" /> 

现在,当我点击一个与我们相关的链接时,它会打开webview应用程序,但是它没有打开正确的页面,它只是再次启动应用程序。 但是我想直接打开webview应用程序中的正确页面。

编辑:

  @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //added Intent intent = getIntent(); String action = intent.getAction(); Uri data = intent.getData(); 

但似乎没有使用变量操作和数据。 我加载这样的webview(三种语言)。

  //loads the main website //sets the matching language web2.clearCache(true); String loc = Locale.getDefault().toString(); if (loc.startsWith("de")) { web2.loadUrl("https://www.example.de"); } else if (loc.startsWith("nl")) { web2.loadUrl("https://www.example.nl"); } else { web2.loadUrl("https://www.example.com"); } 

您必须使用您的活动通过深层链接打开时收到的意图数据。 Kotlin示例:

 class WebViewActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_webview) val uri = intent.data webView.loadUrl(uri.toString()) } 

现在我这样做了。 这是解决方案。

 Intent intent = getIntent(); Uri data = intent.getData(); String loc = Locale.getDefault().toString(); if (data==null && loc.startsWith("de")) { web2.loadUrl("https://www.example.de"); } else if (data==null && loc.startsWith("nl")) { web2.loadUrl("https://www.example.nl"); } else if (data==null && !loc.startsWith("de") && !loc.startsWith("nl")){ web2.loadUrl("https://www.example.com"); } else { web2.loadUrl(data.toString()); } 
Interesting Posts