【问题标题】:How to open specific activity after install an app from Google Play Store for a deep link从 Google Play 商店安装应用程序后如何打开特定活动以获取深层链接
【发布时间】:2019-03-27 04:15:03
【问题描述】:

在我从 Play 商店安装我的应用程序后,有什么方法可以打开某些特定的活动/页面,Play 商店的 url 来自 deeplink(在这种情况下,deeplink/url 来自 QR 码)?

我希望用户将根据深度链接被定向到特定页面

【问题讨论】:

标签: android android-intent deeplink


【解决方案1】:

要使用深度链接打开特定屏幕,您需要实现 深度链接功能并在 Manifest 文件中添加特定屏幕。 请参考以下示例来实现深度链接:

https://medium.com/@muratcanbur/intro-to-deep-linking-on-android-1b9fe9e38abd

【讨论】:

  • 如果用户还没有下载应用怎么办,下载应用后如何识别深层链接并引导用户访问特定页面?
  • 你能告诉我真正想要什么吗?我看不懂
  • 让我说,我在 Playstore 上有我的应用程序的 url,当用户下载并安装它时,它将引导用户到特定页面。该怎么做?
【解决方案2】:

在 2020 年,这就是这样做的方式。您需要将您需要的内容作为推荐 URL 的一部分传递。下面的代码使用SharedPreferences 来存储一个标志,因此它只会处理一次引荐 URL。

在您的build.gradle 文件中

dependencies {
    ....
    implementation 'com.android.installreferrer:installreferrer:2.1'
}

在你的AndroidApplication

import android.content.SharedPreferences;
import android.os.RemoteException;
import com.android.installreferrer.api.InstallReferrerClient;
import com.android.installreferrer.api.InstallReferrerStateListener;
import com.android.installreferrer.api.ReferrerDetails;
import com.badlogic.gdx.backends.android.AndroidApplication;

public class YourApplication extends AndroidApplication {

    public static final String REFERRAL_PROCESSED = "referral-processed";

    private void checkInstallReferralLink() {
        final SharedPreferences prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(this);
        if (prefs.getBoolean(REFERRAL_PROCESSED, false))
            return;

        final InstallReferrerClient referrerClient;

        referrerClient = InstallReferrerClient.newBuilder(this).build();
        referrerClient.startConnection(new InstallReferrerStateListener() {
            @Override
            public void onInstallReferrerSetupFinished(int responseCode) {
                switch (responseCode) {
                    case InstallReferrerClient.InstallReferrerResponse.OK:
                        ReferrerDetails response;
                        try {
                            response = referrerClient.getInstallReferrer();
                            if (response != null) {
                                String referrerUrl = response.getInstallReferrer();
                                if (referrerUrl != null) {
                                    processReferralUrl(referrerUrl);
                                }
                            }

                            SharedPreferences.Editor editor = prefs.edit();
                            editor.putBoolean(REFERRAL_PROCESSED, true);
                            editor.apply();
                        } catch (RemoteException e) {
                            e.printStackTrace();
                        }
                        break;
                    case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                    case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                    case InstallReferrerClient.InstallReferrerResponse.DEVELOPER_ERROR:
                    case InstallReferrerClient.InstallReferrerResponse.SERVICE_DISCONNECTED:
                        break;
                }
            }

            @Override
            public void onInstallReferrerServiceDisconnected() {
            }
        });
    }

    private void processReferralUrl(String referrerUrl) {
        // Do what you need to here
    }
}

【讨论】:

  • 指向 Google Play 商店中包含这些额外数据的应用的 url 格式是什么?
【解决方案3】:

您需要使用包含

的意图过滤器声明接收器
<action android:name="com.android.vending.INSTALL_REFERRER" />

然后通过key“referrer”从intent中获取数据

@Override
public void onReceive(Context context, Intent intent) {
    String rawReferrerString = intent.getStringExtra("referrer");
    if(rawReferrerString != null) {
        Log.i("MyApp", "Received the following intent " + rawReferrerString);
    }
}

https://developer.android.com/google/play/installreferrer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-27
    • 2023-04-03
    • 2019-05-04
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 1970-01-01
    • 2016-12-23
    相关资源
    最近更新 更多