【问题标题】:How to open my app with deep linking instead of redirecting to google play store site?如何使用深层链接打开我的应用,而不是重定向到 Google Play 商店网站?
【发布时间】:2020-10-20 11:03:41
【问题描述】:

当用户点击链接时,我尝试直接打开我的应用,而不打开 google play 商店或浏览器。

我试过这段代码:

     <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">

        <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="fptest"
                android:host="forgot"
                android:pathPrefix="/"/>
        </intent-filter>
    </activity>

I'm using link as follows

<a href="intent://TestApplication#Intent;scheme=fptest;package=com.example.testapplication;end">  
   Open App
 </a>

where , 
   TestApplication -- my app name
   package -- com.example.testapplication

但它总是打开 Google Play 或浏览器,而不是我的应用。

我想从链接打开我的应用程序,例如:fptest://forgot。我不想使用 http 作为方案

【问题讨论】:

    标签: android deep-linking intentfilter


    【解决方案1】:

    您可以通过以下代码实现此目的。如果您打开自己的应用程序,则无需更改任何内容。但是,如果您愿意打开其他应用,只需将 getPackageName 更改为该特定应用即可。

    @SuppressLint("WrongConstant")
        public void OpentheApp()
        {
            Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + getPackageName()));
            localIntent.addFlags(1208483840);
            try
            {
                startActivity(localIntent);
            }
            catch (Exception localException)
            {
                startActivity(new Intent("android.intent.action.VIEW", Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
            }
        }
    

    如果你想通过webview打开它。然后按照这个: 在 Activity 上声明这两个。

    String market_url = "market://details?id=package_name";
    String website_url = "https://play.google.com/store/apps/details?id=package_name";
    

    在 OnCreate 内部:

    WebView webview = (WebView) findViewById(R.id.webview);
    webview.loadUrl("file:///android_asset/index.html");               // path to html
    webview.setWebViewClient(new Callback());
    
    
        private class Callback extends WebViewClient {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url.equals(website_url)) {
                    try {
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(market_url));
                        startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                    }
                }
                return (false);
            }
        }
    

    index.html

    <a href="https://play.google.com/store/apps/details?id=package_name">App link</a>
    

    它将在 Play 商店中打开应用程序。

    【讨论】:

    • 您好,感谢您的宝贵时间。我想打开我自己的应用程序,它安装在我的设备中。实际上,我的功能是发送邮件链接以重置密码。单击链接后,我们的应用程序应该会打开(如果已安装)。我不想开游戏商店。如果我提供方案 http ,则应用程序将打开。但我不想添加 http ,我的网址是例如:fptest://forgot
    【解决方案2】:
    <data
           android:host="www.yourdomain.com"
           android:pathPrefix="/api/forgot"
           android:scheme="https"
    </data>
    

    然后处理onCreate()onNewIntent()中的数据。 您的主机应该是传入 url 的完整域。 PathPrefix 应该是路径段 并且方案应该可以是 http/https/etc 中的任何一个

    您可以使用如下 URL:- https://www.yourdomain.com/api/forgot/abc.php

    【讨论】:

    • 您好,感谢您的宝贵时间。我想使用自定义方案(不是 https/http)。
    【解决方案3】:

    将此添加为您的链接

    <a href="intent://forgot#Intent;scheme=fptest;package=com.example.testapplication;end">  
       Open App
     </a>
    

    注意:我将 TestApplication 替换为 forgot you need to use host after intent://

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 2019-11-27
      • 2016-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多