IOException in mReferrerClient.getInstallReferrer() with HMS Core version 5.0.1.307

715 Views Asked by At

I want to test my own app before going live after integrating with Huawei install Referrer SDK. I followed all the steps found in codelabs and the documentations and when i install the apk on the device , getInstallReferrer method throws IOException. This is my code. What is it that i am doing wrong ?. how can i get installReferrer info for testing purposes ?

       Runnable {
            referrerClient = newBuilder(context).setTest(true).build()
            referrerClient.startConnection(object : InstallReferrerStateListener {

                @SuppressLint("SwitchIntDef")
                override fun onInstallReferrerSetupFinished(responseCode: Int) {
                    when (responseCode) {
                        InstallReferrerClient.InstallReferrerResponse.OK -> {
                            // Connection established.
                            try {
                                val response: ReferrerDetails = referrerClient.installReferrer
                                val referrerUrl: String = response.installReferrer
                                val referrerClickTime: Long = response.referrerClickTimestampSeconds
                                val appInstallTime: Long = response.installBeginTimestampSeconds
                            }catch (e : IOException){
                                Log.i("INSTALL_REFERRER","IOException")
                            }
                            catch(e: RemoteException){
                                Log.i("INSTALL_REFERRER","RemoteException")
                            }
                            finally {
                                referrerClient.endConnection()
                            }


                        }
                        InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
                           
                            Log.i("INSTALL_REFERRER","NOT AVAILABLE")
                        }
                        InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
                           
                            Log.i("INSTALL_REFERRER","SERVICE UNAVAILABLE")
                        }
                    }
                }

                override fun onInstallReferrerServiceDisconnected() {
                    Log.i("INSTALL_REFERRER","ReferrerServiceDisconnected")
                }
            })
        }.run()
1

There are 1 best solutions below

6
zhangxaochen On

Please check whether the AIDL interface is added.

Check the screenshot below: enter image description here

  • Obtain Install Referrer Information by AIDL

You can call an AIDL API provided by HUAWEI Ads Kit to obtain install referrer information from HUAWEI devices, without integrating any HUAWEI SDK. The install referrer information obtained from a device in either mode (SDK or AIDL) is the same.

  • Call Process enter image description here

  • The Development Procedure is as follows

  1. Create an AIDL file for the IPPSChannelInfoService API and save the file.

  2. Copy the following content to the AIDL file:

    package com.huawei.android.hms.ppskit;
    /** Important: Do not change the method sequence in the AIDL file. */
    interface IPPSChannelInfoService {
    String getChannelInfo();
    }

  3. Change Build Action to AndroidInterfaceDescription of AIDL file.

  4. Rebuild project.

  5. Create a class to implement Android-native IServiceConnection.

For more details, see docs. Also, please kindly refer to the demo.

Update:

  1. The package name needs to be specified because setTest(true)

    if (this.isTest){ var2 = "com.huawei.pps.hms.test"; }

  2. The empty check on ReferrerDetails can be added.

    if (null != referrerDetails && null != mCallback)