- Home /
How can I respond to the Android broadcast "com.android.vending.INSTALL_REFERRER"?
We are migrating an Android app to Unity and one of the things the Android app does, is register itself as a broadcast receiver through the AndroidManifest like this:
<receiver
android:name="com.example.OurReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
The Android BroadcastReceiver is implemented like this:
public class OurReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String referrer = intent.getStringExtra("referrer");
// do stuff with the referrer
}
}
Assuming I have C# code ready to do the stuff with the referrer, how can I do this in Unity?
I am too interested in this and I'm shocked that there's so little information on this topic.
Answer by liortal · Aug 15, 2014 at 08:37 AM
What you need in order to achieve this:
A custom JAR that contains your Java code (with the BroadcastReceiver).
A custom AndroidManifest.xml like you posted that Unity will use.
Some way of calling from the Java VM back into Unity.
Assuming you have a Java project wuth the BroadcastReceiver, you would need to compile it to JAR. Place the JAR in your Unity project under Assets/Plugins/Android
Also place the AndroidManifest.xml in that folder.
In order to call back into your scripting code from Java, use the UnityPlayer.UnitySendMessage.
See the documentation here on how to use it: http://docs.unity3d.com/Manual/PluginsForAndroid.html