Search code examples
androidunity-game-engineinstall-referrer

Install Referrer in Unity3D


Tell me how you can get install referrer in Unity3D. I made an android plugin in which I created a class inherited from the broadcastreceiver. And in the onreceive method, I send data, but the onreceive method is not called. The receiver has been added to the plugin Manifest and Unity manifest.Manifest:

<receiver
    android:name="com.ahg.and.InstallReferrerReceiver"
    android:exported="true"
    android:permission="android.permission.INSTALL_PACKAGES">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

BroadcastReceiver:

public class InstallReferrerReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String referrer = intent.getStringExtra("referrer");

        UnityPlayer.UnitySendMessage("Loader", "GetReferrer",referrer);
    }
}

Please tell me, for what reason is not called broadcastreceiver?


Solution

  • I will write to those who are interested in this problem: in OnReceive you need to call non-unity methods ( since broadcastreceiver is called before the application starts) then I save string referrer through sharedpreferences , and then check it in unity at startup. I hope this helps someone.