android - 如何使用自定义链接打开我的 Android 应用程序?

标签 android android-intent android-manifest deep-linking

我想通过 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/

相关文章:

Android 架构组件、android 绑定(bind)和 LiveData

android - 如何标记具有许多不同字符的字符串?

android - 什么时候使用 FLAG_ACTIVITY_RETAIN_IN_RECENTS?

java - 是否有使用播客应用程序订阅提要的标准方法?

Android 主题不适用于 Activity

android - 由于 : 'Failed to commit install session 881743286 with command cmd package install-commit 881743286 安装失败

java - 我可以在 Android 上使用 PixelMed 吗?

android - 组织.gradle.api.tasks.TaskExecutionException : Execution failed for task ':mergeDevOnlySlDebugResources' only on Jenkins

java - 如何在 bundle 中传递 list<>

安卓单点登录