I'm trying to log what comes from installing app from store. But my custom receiver does not work when actual installation from Play Market occurs, however it works when I'm using adb to broadcast something like this.
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n "package_name"/.InstallReceiver --es referrer "TOPKEK"
Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp="package_name"/.InstallReceiver (has extras) }
Receiver works as expected:
D/InstallReceiver: onReceive() called with: context = [android.app.ReceiverRestrictedContext@2af18590], intent = [Intent { act=com.android.vending.INSTALL_REFERRER flg=0x10 cmp="package_name"/.InstallReceiver (has extras) }extras=[Bundle{referrer='TOPKEK'}]]
But when installing from Google Play App the only thing in log is message from CampaignTrackingReceiver: "CampaignTrackingReceiver is not registered, not exported or is disabled. Installation campaign tracking is not possible. See http://goo.gl/8Rd3yj for instructions."
Code of receiver:
package "package_name";
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.adjust.sdk.AdjustReferrerReceiver;
import "package_name".util.LogHelper;
public final class InstallReceiver extends BroadcastReceiver {
private static final String TAG = "InstallReceiver";
@Override
public void onReceive(final Context context, final Intent intent) {
Log.d(TAG, "onReceive() called with: " + "context = [" + context + "], intent = [" + LogHelper.format(intent) + "]");
new AdjustReferrerReceiver().onReceive(context, intent);
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="package_name"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- normal permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<permission
android:name="'package_name'.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="'package_name'.permission.C2D_MESSAGE"/>
<application
android:name=".CustomApplication"
android:allowBackup="true"
android:fullBackupContent="false"
android:icon="@drawable/menu_icon_earny"
android:label="@string/app_name"
android:theme="@style/AppTheme">
//activities here
//gcm stuff
<!-- Google Analytics -->
<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH"/>
</intent-filter>
</receiver>
<service
android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false"/>
<!--My install receiver that didn't work as intended-->
<receiver
android:name=".InstallReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
</application>
</manifest>
UPD: I need my receiver to work, I need that log not google receiver.
Your receiver is working - I just checked it in production. In order to test your receiver, you need to use a URL with the various UTM parameters defined in Google's docs - you can't just install it directly from Google Play. Here's proof from my logcat:
0-16 09:08:45.408 13634 13634 D InstallReceiver: onReceive() called with: context = [android.app.ReceiverRestrictedContext@1cf1a5b], intent = [Intent { act=com.android.vending.INSTALL_REFERRER flg=0x10 pkg=com.cashcowlabs.earny cmp=com.cashcowlabs.earny/.InstallReceiver (has extras) }extras=[Bundle{referrer='utm_source=google&utm_medium=cpc&utm_term=podcast%2Bapps&utm_content=displayAd1&utm_campaign=podcast%2Bgeneralkeywords'}]]
The error ("CampaignTrackingReceiver is not registered..") to which you're referring is misleading and doesn't mean that your receiver is failing.
Looks like you're using the Google Analytics SDK, which likely, on initialization, inspects your app's manifest, looking for CampaignTrackingReceiver
, and when it is not found, it gives you that warning. This is just a warning, and is a case of the Google Analytics SDK developers trying to help you out, but ending up confusing you more :).
If you want to get the GA broadcast receiver working, you could change your code to delegate the referrer intent to it, just as you're doing for Adjust:
@Override
public void onReceive(final Context context, final Intent intent) {
Log.d(TAG, "onReceive() called with: " + "context = [" + context + "], intent = [" + LogHelper.format(intent) + "]");
new AdjustReferrerReceiver().onReceive(context, intent);
new CampaignTrackingReceiver().onReceive(context, intent);
}
It looks like, according to Google's docs, you should also add their service to your manifest. My guess is that CampaignTrackingReceiver
delegates its work to the service, but you can check out the decompiled jar to find out for yourself. Add this to your manifest, right where you define the other GA service:
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
The warning about the receiver not being found may still be there, but as long as your see attributed installs in Adjust and Google Analytics (test it by downloading your app using a