Prepare a Huawei phone running HMS Core (APK) 2.6.5 or later. After completing the above install referrer service code, you can compile the code. If an error occurs during the compilation, modify the code as prompted. After the compilation is complete, an .apk file is generated and installed.
Install referrer information can be obtained only after an ad is delivered on HUAWEI Ads. A demo is provided here to generate install referrer information on the device for you to test your app. For details about the demo download address, please refer to Sample Code.
2.1 SDK Mode
When creating InstallReferrerClient, set the test mode by calling setTest(true), as shown below:
- mReferrerClient = InstallReferrerClient.newBuilder(mContext).setTest(true).build();
- mReferrerClient.startConnection(installReferrerStateListener);
2.2 AIDL Mode
During the testing, set the name of the bound AIDL service package to com.huawei.pps.hms.test, as shown below:
- mServiceConnection = new InstallReferrerServiceConnection();
- Intent intent = new Intent("com.huawei.android.hms.CHANNEL_SERVICE");
- intent.setPackage("com.huawei.pps.hms.test");
- boolean result = mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
- Log.i(TAG, "bindService result: " + result);
If logs show that the install referrer information has been correctly obtained, your app has correctly integrated the install referrer capability.
