# Android - OpenInstall Integration to Android [Three, function integration] ###### tags: `Android` [TOC] # Introduction ## What is OpenInstall? In simple words, we can use openinstall to get channel statistics. ## This tutorial objective We can head to [OpenInstall Website](https://developer.openinstall.io/) to checkout the latest information about OpenInstall. As for **"How to integrate it to Android SDK"**, you can just [click here](https://www.openinstall.io/doc/android_sdk.html) for further information. # 1. Deal OpenInstall JAR ## 1.1 Download OpenInstall JAR First, you have to download the latest [OpenInstall Jar](https://www.openinstall.io/download.html) and unzip it. ## 1.2 Set up Location Get the Jar you obtained and put it in your project's **libs folder (projectRoot/app/libs)**. Note: For those you do not know, all jars in project are put there. ## 1.3 Set up openinstall implementation Therefore, you will get yourself to **build.gradle(:app)** and add it to your dependencies. **For just OpenInstall Implementation:** ```java= implementation files('libs/OpenInstall_vX.X.X.jar') ``` **For all JARs:** ```java= implementation fileTree(dir: 'libs', include: ['*.jar']) ``` # 2. Set up Manifest ## 2.1 Uses-permission Make sure you have **Internet** and **Access Network State** opened. ```java= <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> ``` ## 2.2 Set openinstall appkey and scheme Must set it up inside **application** tag. **meta-data:** ```java= <meta-data android:name="com.openinstall.APP_KEY" android:value="OPENINSTALL_APPKEY"/> ``` ```java= <activity android:name=".MainActivity" android:launchMode="singleTask"> // Need Intent-Filter if it is firstpage and splash page <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="OPENINSTALL_APPKEY"/> </intent-filter> </activity> ``` ![](https://i.imgur.com/91DCA3b.png) # 3. Init SDK When the app is started, **OpenInstall.init(context)** must be called to complete the SDK initialization. ```java= OpenInstall.init(this); ``` # 4. Methods already used Inside the Activity that has the **scheme** set up in manifest, we will call the following methods: 1. OpenInstall.getWakeUp 2. OpenInstall.getInstall ## OpenInstall.getWakeUp(intent, wakeUpAdapter) By using this method, you can obtain some parameters. Though you must remember to make wakeAdapter null when the activity is being destroyed. ```java= public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Get Wakeup Parameters OpenInstall.getWakeUp(getIntent(), wakeUpAdapter); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); // Must be called here in case, app is running on background OpenInstall.getWakeUp(intent, wakeUpAdapter); } AppWakeUpAdapter wakeUpAdapter = new AppWakeUpAdapter() { @Override public void onWakeUp(AppData appData) { //Get Channel Data String channelCode = appData.getChannel(); //Get Bound Data String bindData = appData.getData(); Log.d("OpenInstall", "getWakeUp : wakeupData = " + appData.toString()); } }; @Override protected void onDestroy() { super.onDestroy(); wakeUpAdapter = null; } } ``` ## OpenInstall.getInstall Get Data when you need it. ```java= OpenInstall.getInstall(new AppInstallAdapter() { @Override public void onInstall(AppData appData) { //Get Channel Data String channelCode = appData.getChannel(); //Get Custom Data String bindData = appData.getData(); Log.d("OpenInstall", "getInstall : installData = " + appData.toString()); } }); ``` # 5. Other Methods available for usage ## 5.1 OpenInstall.reportRegister To count amount of registrations per channel, we need to use: ```java= OpenInstall.reportRegister(); ``` # Statistic in Openinstall After code integration, you need to export the apk and upload it to openinstall in website.