0

我想实现 Play Install Referrer API,我找到了文档并阅读了该文档,但我有些困惑。首先我实现了谷歌提供的所有代码。但我想知道我需要创建哪种类型的 url,以便用户可以单击链接并去玩商店并安装我的应用程序,然后我得到推荐详细信息..

我使用这段代码:

   InstallReferrerClient mReferrerClient;
    mReferrerClient = newBuilder(this).build();
    mReferrerClient.startConnection(this);

    @Override
    public void onInstallReferrerSetupFinished ( int responseCode){
        switch (responseCode) {
            case InstallReferrerClient.InstallReferrerResponse.OK:
                // Connection established

           /* ReferrerDetails response = null;
            try {
                response = mReferrerClient.getInstallReferrer();
                response.getInstallReferrer();
                response.getReferrerClickTimestampSeconds();
                response.getInstallBeginTimestampSeconds();
            } catch (RemoteException e) {
                e.printStackTrace();
            }*/


                break;
            case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                // API not available on the current Play Store app
                break;
            case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                // Connection could not be established
                break;
        }
    }
    @Override
    public void onInstallReferrerServiceDisconnected () {

    }

但是我创建了哪种类型的链接,所以用户去播放商店,安装播放商店推荐 api 后给我数据..

4

2 回答 2

0

示例网址 -"https://play.google.com/store/apps/details?id=com.dummy.app&referrer=referralCode%3D311566%26source%3DFacebook+App"

使用 Google Play Referrer API 时 -

InstallReferrerClient mReferrerClient;
    mReferrerClient = newBuilder(this).build();
    mReferrerClient.startConnection(this);

    @Override
    public void onInstallReferrerSetupFinished ( int responseCode){
        switch (responseCode) {
            case InstallReferrerClient.InstallReferrerResponse.OK:
                // Connection established

           /* ReferrerDetails response = null;
            try {
                response = mReferrerClient.getInstallReferrer();
                response.getInstallReferrer();
                response.getReferrerClickTimestampSeconds();
                response.getInstallBeginTimestampSeconds();
            } catch (RemoteException e) {
                e.printStackTrace();
            }*/
            
                // End the connection once you get the data
                referrerClient.endConnection();

                break;
            case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                // API not available on the current Play Store app
                break;
            case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                // Connection could not be established
                break;
        }
    }
    @Override
    public void onInstallReferrerServiceDisconnected () {

    }

getInstallReferrer()

将返回 String 'referralCode=311566&source=Facebook App'

于 2021-06-14T06:52:09.400 回答
0

播放安装推荐库我想用简单的措辞来描述这一点,作为一名开发人员,您想了解这些元素您的应用程序包需要多少时间才能从 Play 商店安装到用户设备上,以及推荐网址、推荐点击时间等等元素,谷歌让你很容易知道你必须为此目的使用播放安装推荐库。

添加此依赖项

implementation 'com.android.installreferrer:installreferrer:1.1'

您可以遵循此处的指南:

播放安装程序推荐指南

在任何 java 活动中声明此变量

InstallReferrerClient referrerClient;

在创建方法中使用以下代码:

 referrerClient = InstallReferrerClient.newBuilder(this).build();
    referrerClient.startConnection(new InstallReferrerStateListener() {
        @Override
        public void onInstallReferrerSetupFinished(int responseCode) {
            switch (responseCode) {
                case InstallReferrerClient.InstallReferrerResponse.OK:
                    // Connection established.
                    break;
                case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                    // API not available on the current Play Store app.
                    break;
                case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                    // Connection couldn't be established.
                    break;
            }
        }


        @Override
        public void onInstallReferrerServiceDisconnected() {
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
        }


    });

在 onInstallReferrerSetupFinished stabled 中,您可以轻松获取这些数据,之后您的代码将像这样

  ReferrerDetails response = null;
                    try {
                        response = referrerClient.getInstallReferrer();
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }
                    String referrerUrl = response.getInstallReferrer();
                    long referrerClickTime = response.getReferrerClickTimestampSeconds();
                    long appInstallTime = response.getInstallBeginTimestampSeconds();
                    boolean instantExperienceLaunched = response.getGooglePlayInstantParam();

整个代码将是这样的

 referrerClient = InstallReferrerClient.newBuilder(this).build();
    referrerClient.startConnection(new InstallReferrerStateListener() {
        @Override
        public void onInstallReferrerSetupFinished(int responseCode) {
            switch (responseCode) {
                case InstallReferrerClient.InstallReferrerResponse.OK:
                    // Connection established.

                    ReferrerDetails response = null;
                    try {
                        response = referrerClient.getInstallReferrer();
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }
                    String referrerUrl = response.getInstallReferrer();
                    long referrerClickTime = response.getReferrerClickTimestampSeconds();
                    long appInstallTime = response.getInstallBeginTimestampSeconds();
                    boolean instantExperienceLaunched = response.getGooglePlayInstantParam();

                    break;
                case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                    // API not available on the current Play Store app.
                    break;
                case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                    // Connection couldn't be established.
                    break;
            }
        }


        @Override
        public void onInstallReferrerServiceDisconnected() {
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
        }


    });

执行

执行

于 2019-12-11T06:55:06.187 回答