我想通过 WhatsApp 和 Telegram 等链接打开我的 Android 应用程序。
(示例)https://chat.whatsapp.com
如果我单击此链接并且安装了 WhatsApp,此链接将打开 WhatsApp 那么我如何在我的应用程序中执行此操作?
最佳答案
如果您想深层链接您的应用程序。例如:您打开一个链接,它应该通过您的应用程序打开。在本例中,我使用以 webView
打开的网站。在你的应用程序中。当然,您可以自定义它。
开始创建<intent-filter>
在你的AndroidManifest.xml
:
<application
<activity
<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:scheme="https"
android:host="yourURL"></data>
...
</intent-filter>
</activity>
</application>
在你的 MainActivity.java
中您编写以下代码来获取webView
中要设置的数据:
Uri uri = getIntent().getData();
if (uri!=null){
String path = uri.toString();
WebView webView = (WebView)findViewById(R.id.webView);
webView.loadUrl(path);
}
还有你的webView
在您的 activity_main.xml
中定义:
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView"/>
就是这样。祝你好运!干杯:)
关于android - 如何使用自定义链接打开我的 Android 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67350945/