【问题标题】:how to open my app by clicking on links of my website [duplicate]如何通过单击我网站的链接来打开我的应用程序[重复]
【发布时间】:2018-03-01 07:53:57
【问题描述】:

我有一个网站,我有一个简单的应用程序,它有一个简单的 web 视图。

当每个人都安装了应用程序后,他们可以点击指向我网站的链接。然后那些应该在我的应用程序中打开。

例如,如果我的网站是 www.zoomit.ir,我在 insta 或电报等社交应用中点击 https://www.zoomit.ir/2016/10/8/146994/todoist-tasklist-mobile-app/,打开我的应用并显示该链接

如何午餐应用程序并获取该链接并在 webview 中显示该链接

【问题讨论】:

标签: android url webview


【解决方案1】:

在您的AndroidManifest.xml 文件中,尝试在您要从链接打开的<activity> 中添加一个意图过滤器

<activity
    android:name=".YourActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>

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

<data
    android:host="www.zoomit.ir"
    android:scheme="http"></data>

</intent-filter>
</activity>

假设www.zoomit.ir 是应该打开应用程序的链接

为了在 webview 中打开这个 url,首先通过在你的活动的onCreate 中使用意图来获取这个 url

    String url;
    Intent intent = getIntent();
    String action = intent.getAction();
    Uri data = intent.getData();

 if (data!=null) {     
 webView.loadUrl(data.getScheme()+"://"+data.getHost()+data.getPath());
    }

现在您将拥有url="www.zoomit.ir/example-post"。使用这个url 加载网页视图

【讨论】:

  • 我想为我网站的其他链接执行此操作,就像我在我的问题中写的那样......
  • 用那个链接替换
  • tnx 但我想通过单击以 zoomit.ir/example-post 开头的所有链接来打开我的应用程序
  • 在您的&lt;data&gt; 中添加android:pathPrefix="example-post",查看更新后的答案
  • 使用此补丁前缀选项...我的应用程序运行并在 webview 中打开该链接?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-04-27
  • 1970-01-01
  • 2019-06-16
  • 1970-01-01
  • 1970-01-01
  • 2017-08-07
  • 2016-10-10
相关资源
最近更新 更多