Objective
1. Unity Integrated Openinstall SDK?
Recently, using an SDK called Openinstall, it has been integrated into unity game development by implementing the function of the free invitation code. Optimization of the app installation process, especially the free-fill invitation code installation, the app promotion of the prize invitation activities to achieve greater extent to promote the explosive effect.
Customize various dynamic parameters (such as promotion channel number, invitation code, game room number, user ID, etc.) in the Share link. The effect of the no-fill invitation code can be achieved by attaching the user ID of the app inviter to the URL of the share link, or the app can establish a direct-to-game room by attaching a game room number in the URL; Unity development will inevitably invite users to receive rewards; New and old users to the game scene ; Pull up the game scene from a variety of browsers and so on;
So how do you integrate openinstall in unity? Say no more, bar ~ haha
2. Register/Login Openinstall developer Platform http://developer.openinstall.io/and create an app
Work first in the Androidstudio.
New Project
Just be aware that the package name of the new project in Androidstudio (hereinafter referred to as) is consistent with the package name set by Unity when publishing Android.
2. Importing the JAR Package
将Unity路径下的接口classes.jar导入到AS的libs目录下,然后sync一下项目。接口包所在地:(E:\ProgramFiles\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Release\Classes\classes.jar)
Likewise, go to the Openinstall official website to download the Openinstall_vx.x.x.jar into the as Libs directory, sync the project
3. Writing mainactivity Code
Write mainactivity inherit from unityplayeractivity
Import android.content.Intent; Import Android.os.Bundle; Import Android.util.Log; Import Com.fm.openinstall.OpenInstall; Import Com.fm.openinstall.listener.AppInstallListener; Import Com.fm.openinstall.listener.AppWakeUpAdapter; Import Com.fm.openinstall.model.AppData; Import Com.fm.openinstall.model.Error; Import Com.unity3d.player.UnityPlayer; Import com.unity3d.player.UnityPlayerActivity; public class Mainactivity extends Unityplayeractivity {///1, note modify the integrated class, change to unityplayeractivity @Override protected VO ID onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Getinstall ()///Personalized installation Openinstall.getwakeup (Getintent (), wakeupadapter);//Get wake-up parameter} @Override Protec Ted void Onnewintent (Intent Intent) {super.onnewintent (Intent); Openinstall.getwakeup (Intent, wakeupadapter); } appwakeupadapter Wakeupadapter = new Appwakeupadapter () {@Override public void Onwakeup (final ApPData appData) {//Get channel data String Channelcode = Appdata.getchannel (); Gets the binding data String Binddata = Appdata.getdata (); Callback data Object name, script method, returned data unityplayer.unitysendmessage ("Main Camera", "Wakeup", "data=" +binddata+ "; channelcode=" +c Hannelcode); } }; /** * When the app needs to personalize the installation parameters (by the Web page passed, such as the invitation code, game room number, etc.) * Call the Openinstall.getinstall method, get the parameters in the callback (repeatable access) * For the Free invitation code installation, auto add friends, channel statistics and other installation source tracking solutions */public void Getinstall () {////////////////////////////////// Save the data Openinstall.getinstall (new Appinstalllistener () {@Override Pub LIC void Oninstallfinish (AppData AppData, error error) {LOG.D ("Openinstall", "installfinish"); if (Error = = NULL) {//data returned based on its own business String Pdata.getdata (); String ChaNnelcode = Appdata.getchannel (); Callback data Object name, script method, returned data unityplayer.unitysendmessage ("Main Camera", "Install", "Data=" +data+ "; channe Lcode= "+channelcode); } else {log.e ("mainactivity", "errormsg:" + error.tostring ()); } } }); }//Data escalation statistics public void reportregister () {openinstall.reportregister (); } @Override protected void OnDestroy () {Super.ondestroy (); Wakeupadapter = null; } }
4. Custom application class app inherits application and initializes
- Modify Androidmanifest.xml
Add a rights statement in Androidmanifest.xml, set Appkey, configure scheme
Add Android:name= "to the application tag in Androidmanifest.xml. APP "Specifies the custom application class so that when the program starts, it initializes the custom application class instead of the system default application class
- Modify Build.gradle
7. Production of ARR packages
Build->build apk success will appear in the App\build\outputs\aar directory of a App-debug.aar package (here is the debug package), and then use the decompression software to open the package, delete libs under the Classes.jar ( Yes, it was the previous re-classes.jar in unity) because unity will re-bring the self-contained in the package, if not deleted it will be packaged error, conflict and then this is the final need of the AAR package, the AAR package decompression, see Classes.jar ( The Classes.jar here is the project build, not the same as the Classes.jar in the Libs file in as, and the Classes.jar and Androidmanifest.xml under the AAR are placed in one place waiting to be used in unity
Call in Unity
Unity Create a new project, set up JDK, Android SDK.
Finally in the Assets directory to create a new directory we need, assets\plugins\android, and put androidmanifest.xml inside.
Then create the directories we need in the Assets directory, Assets\plugins\android\libs, and place the Classes.jar and Openinstall_vx.x.x.jar under the AAR.
Unity calls Android method
Create a new script in camera main Main.cs call the Android method (the reflection mechanism gets the Android method)
Call methods according to your business needs, such as
public class Main : MonoBehaviour { public Text txtWakeup; public Text txtInstall; void Start() { txtWakeup = GameObject.Find("Canvas/txtWakeup").GetComponent<Text>(); txtInstall = GameObject.Find("Canvas/txtInstall").GetComponent<Text>(); AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"); jo.Call("getInstall"); //jo.Call("reportRegister"); //上报注册统计 txtWakeup.text = "唤醒参数"; txtInstall.text = "安装参数"; } //接收Android回调的数据 wakeup方法 void wakeup(string str) { txtWakeup.text = str; } //接收Android回调的数据,install方法 void install(string str) { txtInstall.text = str; } }
Package upload install package to Openinstall background test:
After uploading the APK installation package, you can use the online test function provided by Openinstall to ensure that the dynamic parameters of the input can be correctly restored after the app is installed, and the app can be pulled up normally.
Note: After getting the Openinstall callback data, the specific business can be handled specifically!
Demo:https://github.com/annecr/unity-openinstall/tree/master
Unity Integrated Openinstall Process