如何通过点击我的网站链接打开我的应用程序[重复]

问题描述 投票:-1回答:1

这个问题在这里已有答案:

我有一个网站,我有一个简单的应用程序,有一个简单的webview。

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

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

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

android url webview
1个回答
0
投票

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

<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中使用intent获取此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加载webview

© www.soinside.com 2019 - 2024. All rights reserved.