Android SDK v4.3.11 test

Getting Started

Latest Android version: 5.0.1
Release date: 16-Mar 2020
Latest Android version: 5.0.1
Release date: 16-Mar 2020

This document details the process of integrating YouAppi’s SDK with your Android app. This document details the process of integrating YouAppi’s SDK with your Android app.
If you have any questions, please, feel free to email us: support@youappi.com If you have any questions, please, feel free to email us: support@youappi.com
The basic steps of integration are: The basic steps of integration are:

    • Add our SDK AAR and dependencies to your project.
    • Add our SDK AAR and dependencies to your project.
    • Init the SDK.
    • Init the SDK.
    • Load an ad.
    • Load an ad.
    • Show an ad.
    • Show an ad.

Requirements: Requirements:
Minimum API level: 16, Android 4.1 Minimum API level: 16, Android 4.1
Please, note that SDK can access some of user’s private information, so, make sure you have read this part carefully. Please, note that SDK can access some of user’s private information, so, make sure you have read this part carefully.

Integration

Integration

Integrate using AAR file

Integrate using AAR file

Our latest SDK version can be downloaded as a ZIP file from the following URL: Our latest SDK version can be downloaded as a ZIP file from the following URL:
YouAppi Android SDK YouAppi Android SDK
The ZIP file contains: The ZIP file contains:

    • SDK AAR file – youappi-sdk-android-moat.aar – YouAppi’s SDK
    • SDK AAR file – youappi-sdk-android-moat.aar – YouAppi’s SDK
    • SDK AAR file – youappi-sdk-android-admob.aar – YouAppi’s AdMob adapter
    • SDK AAR file – youappi-sdk-android-admob.aar – YouAppi’s AdMob adapter
    • SDK AAR file – youappi-sdk-android-mopub.aar – YouAppi’d MoPub adapter
    • SDK AAR file – youappi-sdk-android-mopub.aar – YouAppi’d MoPub adapter
    • Copy youappi-sdk-android-moat.aar file to the apps\libs folder of your project.
    • Copy youappi-sdk-android-moat.aar file to the apps\libs folder of your project.
    • Add the following to the project build.gradle file inside the repositories section:
    • Add the following to the project build.gradle file inside the repositories section:
      repositories {	 	
      repositories {
          flatDir {	 	    flatDir {
              dirs 'libs'	 	        dirs 'libs'
          }	 	    }
      }

      }

  • Add to your app build.gradle file the following under dependencies section:
  • Add to your app build.gradle file the following under dependencies section:
    dependencies {	 	
    dependencies {
        implementation name:'youappi-sdk-android-moat', ext:'aar'	 	    implementation name:'youappi-sdk-android-moat', ext:'aar'
        implementation 'com.google.code.gson:gson:2.6'	 	    implementation 'com.google.code.gson:gson:2.6'
    }

    }

  • Note: If Manifest Merger is disabled, the following items need to be added to the AndroidManifest.xml file: Note: If Manifest Merger is disabled, the following items need to be added to the AndroidManifest.xml file:

      • Add AdActivity activity to <application> tag :
      • Add AdActivity activity to <application> tag :
        <activity android:name="com.youappi.sdk.AdActivity"	 	
        <activity android:name="com.youappi.sdk.AdActivity"
           android:configChanges="screenSize|orientation"/>

        android:configChanges="screenSize|orientation"/>

  • These permissions should be added if your app is running on older devices:
  • These permissions should be added if your app is running on older devices:
    <uses-permission android:name="android.permission.INTERNET"/>	 	
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>	 	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>	 	<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

  • Integrate using repository

    Integrate using repository

      • Add the following to the project build.gradle file inside the repositories section:
      • Add the following to the project build.gradle file inside the repositories section:
        maven { url "http://repository.youappi.com/repository/release" }	 	
        maven { url "http://repository.youappi.com/repository/release" }
        

  • Add to your app build.gradle file the following under dependencies section:
  • Add to your app build.gradle file the following under dependencies section:
    dependencies {	 	
    dependencies {
         implementation "com.youappi.sdk:youappi-sdk-android-moat:4.3.10"	 	     implementation "com.youappi.sdk:youappi-sdk-android-moat:4.3.10"
    }

    }

  • Using the SDK

    Using the SDK

  • Please note: it is strongly recommended to initialize YouAppi SDK in the onCreate method of the Application object of your app. It will ensure YouAppi SDK instance is always properly initialized. Here is an example:
  • Please note: it is strongly recommended to initialize YouAppi SDK in the onCreate method of the Application object of your app. It will ensure YouAppi SDK instance is always properly initialized. Here is an example:
    import android.app.Application;	 	
    import android.app.Application;
    import com.youappi.sdk.YouAPPi;	 	import com.youappi.sdk.YouAPPi;
                	 	            
    public class YouAppApplication extends Application {	 	public class YouAppApplication extends Application {
                    	 	                
          private static final String DEMO_TOKEN = "<YOUR_APP_TOKEN>;	 	      private static final String DEMO_TOKEN = "<YOUR_APP_TOKEN>;
     	 	 
          @Override	 	      @Override
          public void onCreate() {	 	      public void onCreate() {
                super.onCreate();	 	            super.onCreate();
     	 	 
               YouAPPi.init(this, DEMO_TOKEN, userConsent);	 	           YouAPPi.init(this, DEMO_TOKEN, userConsent);
          }	 	      }
    }	 	}
    

  • Also, update the corresponding manifest.xml with the Application class name:
  • Also, update the corresponding manifest.xml with the Application class name:
    <?xml version="1.0" encoding="utf-8"?>	 	
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"	 	<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.youappi.sdk.demo">	 	 package="com.youappi.sdk.demo">
     <application	 	 <application
     android:name = ".YouAppApplication"	 	 android:name = ".YouAppApplication"
     android:allowBackup="true"	 	 android:allowBackup="true"
     android:icon="@mipmap/ic_launcher"	 	 android:icon="@mipmap/ic_launcher"
     android:label="@string/app_name"	 	 android:label="@string/app_name"
     ...	 	 ...
     ...	 	 ...
     </application>	 	 </application>
    </manifest>

    </manifest>

  • Create an ad instance for one of YouAppi’s products:
  • Create an ad instance for one of YouAppi’s products:
    YARewardedVideoAd rewardedVideoAd = YouAPPi.getInstance().rewardedVideoAd("test_rewarded_video_ad");	 	
    YARewardedVideoAd rewardedVideoAd = YouAPPi.getInstance().rewardedVideoAd("test_rewarded_video_ad");
    YAInterstitialVideoAd interstitialVideoAd = YouAPPi.getInstance().interstitialVideoAd("test_interstitial_ad");	 	YAInterstitialVideoAd interstitialVideoAd = YouAPPi.getInstance().interstitialVideoAd("test_interstitial_ad");
    YAInterstitialAd interstitialAd = YouAPPi.getInstance().interstitialAd("test_interstitial_ad");

    YAInterstitialAd interstitialAd = YouAPPi.getInstance().interstitialAd("test_interstitial_ad");

  • Please note: YouAppi ad unit id is created and controlled by the app developer. The ad unit id later appears in reports and helps to analyze performance for each ad unit. Any arbitrary value can be selected for ad unit id as long as it is constructed from:
  • Please note: YouAppi ad unit id is created and controlled by the app developer. The ad unit id later appears in reports and helps to analyze performance for each ad unit. Any arbitrary value can be selected for ad unit id as long as it is constructed from:
  • Custom parameters and server-to-server callback (optional)

    Custom parameters and server-to-server callback (optional)

    YouAppi SDK supports customer parameters and server-to-server callback. Custom parameters could be passed during the ad request and received upon user’s completion event as a part of the callback string (server-to-server completion callback).

    YouAppi SDK supports customer parameters and server-to-server callback. Custom parameters could be passed during the ad request and received upon user’s completion event as a part of the callback string (server-to-server completion callback).

    Parameter NameDescriptionValue TypeProvided by
    user_idA unique identifier of the user to be rewarded.StringPublisher
    reward_typeA name of the virtual item to be rewarded.StringPublisher
    reward_valueA number of credit units to be rewarded to the user.StringPublisher
    reward_idA unique identifier of the commission event.StringYouAppi
    dynamicUserIdA unique parameter to verify transaction that could be changed throughout the session.StringPublisher
    Parameter NameDescriptionValue TypeProvided by
    user_idA unique identifier of the user to be rewarded.StringPublisher
    reward_typeA name of the virtual item to be rewarded.StringPublisher
    reward_valueA number of credit units to be rewarded to the user.StringPublisher
    reward_idA unique identifier of the commission event.StringYouAppi
    dynamicUserIdA unique parameter to verify transaction that could be changed throughout the session.StringPublisher

    Callback URL example:

    Callback URL example:
    http://www.app.com?appUserId={user_id}&RewardValue={reward_value}&RewardType={reward_type}&RewardId={reward_id}&DynamicUserId={dynamicUserId}

    http://www.app.com?appUserId={user_id}&RewardValue={reward_value}&RewardType={reward_type}&RewardId={reward_id}&DynamicUserId={dynamicUserId}

    You can use YAAdRequest object to add custom parameters as <key, value> to your ad request before loading an ad: You can use YAAdRequest object to add custom parameters as <key, value> to your ad request before loading an ad:

    YaAdRequest adRequest = new YAAdRequest();	 	
    YaAdRequest adRequest = new YAAdRequest();
    adRequest.addCustomParam("param_key", "param_value");	 	adRequest.addCustomParam("param_key", "param_value");
    rewardedVideoAd.setAdRequest(adRequest);

    rewardedVideoAd.setAdRequest(adRequest);

    Dynamic User Id

    Dynamic User Id

    This optional parameter could be changed throughout the session and used to verify Rewarded Video transactions. To receive this parameter through the server-to-server completion callback, setDynamicUserId() method should be called before calling show(). This parameter will be received with the other custom parameters upon user’s completion event as a part of the server-to-server callback string. This optional parameter could be changed throughout the session and used to verify Rewarded Video transactions. To receive this parameter through the server-to-server completion callback, setDynamicUserId() method should be called before calling show(). This parameter will be received with the other custom parameters upon user’s completion event as a part of the server-to-server callback string.

    YouAPPi.getInstance().setDynamicUserId("best_user_ever");
    YouAPPi.getInstance().setDynamicUserId("best_user_ever");

    Age and Gender support (optional)

    Age and Gender support (optional)

    In order to get better supply that allocated specifically to the user, user’s age and gender could be forwarded to our server throughout YouAppi SDK. You can use YAAdRequest object and setGender() / setAge() methods accordingly before loading ads. In order to get better supply that allocated specifically to the user, user’s age and gender could be forwarded to our server throughout YouAppi SDK. You can use YAAdRequest object and setGender() / setAge() methods accordingly before loading ads.

    YAAdRequest adRequest = new YAAdRequest()	 	
    YAAdRequest adRequest = new YAAdRequest()
     .setGender(YAAdRequest.Gender.Female)	 	 .setGender(YAAdRequest.Gender.Female)
     .setAge("40");

    .setAge("40");

    Implementation example for Rewarded Video

    Implementation example for Rewarded Video

    Please note: this example is for rewarded video. Other products work in a similar way. Please note: this example is for rewarded video. Other products work in a similar way.

      • Create a rewarded video instance:
      • Create a rewarded video instance:
        YARewardedVideoAd rewardedVideoAd = YouAPPi.getInstance().rewardedVideoAd("test_rewarded_video_ad");
        YARewardedVideoAd rewardedVideoAd = YouAPPi.getInstance().rewardedVideoAd("test_rewarded_video_ad");
  • Add rewarded video event listener:

    Add rewarded video event listener:

    rewardedVideoAd.setRewardedVideoAdListener(new YARewardedVideoAd.RewardedVideoAdListener() {	 	
    rewardedVideoAd.setRewardedVideoAdListener(new YARewardedVideoAd.RewardedVideoAdListener() {
                @Override	 	            @Override
                public void onRewarded(String s) {	 	            public void onRewarded(String s) {
                    	 	                
                }	 	            }
     	 	 
                @Override	 	            @Override
                public void onVideoStart(String s) {	 	            public void onVideoStart(String s) {
     	 	 
                }	 	            }
     	 	 
                @Override	 	            @Override
                public void onVideoEnd(String s) {	 	            public void onVideoEnd(String s) {
     	 	 
                }	 	            }
     	 	 
                @Override	 	            @Override
                public void onVideoSkipped(String s, int i) {	 	            public void onVideoSkipped(String s, int i) {
     	 	 
                }	 	            }
     	 	 
                @Override	 	            @Override
                public void onCardShow(String s) {	 	            public void onCardShow(String s) {
     	 	 
                }	 	            }
     	 	 
                @Override	 	            @Override
                public void onCardClose(String s) {	 	            public void onCardClose(String s) {
     	 	 
                }	 	            }
     	 	 
                @Override	 	            @Override
                public void onCardClick(String s) {	 	            public void onCardClick(String s) {
     	 	 
                }	 	            }
     	 	 
                @Override	 	            @Override
                public void onLoadSuccess(String s) {	 	            public void onLoadSuccess(String s) {
     	 	 
                }	 	            }
     	 	 
                @Override	 	            @Override
                public void onLoadFailure(String s, YAErrorCode yaErrorCode, Exception e) {	 	            public void onLoadFailure(String s, YAErrorCode yaErrorCode, Exception e) {
     	 	 
                }	 	            }
     	 	 
                @Override	 	            @Override
                public void onShowFailure(String s, YAErrorCode yaErrorCode, Exception e) {	 	            public void onShowFailure(String s, YAErrorCode yaErrorCode, Exception e) {
     	 	 
                }	 	            }
     	 	 
                @Override	 	            @Override
                public void onAdStarted(String s) {	 	            public void onAdStarted(String s) {
     	 	 
                }	 	            }
     	 	 
                @Override	 	            @Override
                public void onAdEnded(String s) {	 	            public void onAdEnded(String s) {
     	 	 
                }	 	            }
            });

    });

  • Add custom parameters / age / gender (if needed) and load rewarded video ad:
  • Add custom parameters / age / gender (if needed) and load rewarded video ad:
    YAAdRequest adRequest = new YAAdRequest()	 	
    YAAdRequest adRequest = new YAAdRequest()
     .addCustomParam("user_id", "user100")	 	 .addCustomParam("user_id", "user100")
     .addCustomParam("reward_value", "25")	 	 .addCustomParam("reward_value", "25")
     .addCustomParam("reward_type", "coins")	 	 .addCustomParam("reward_type", "coins")
     .setGender(YAAdRequest.Gender.Female)	 	 .setGender(YAAdRequest.Gender.Female)
     .setAge("40");	 	 .setAge("40");
    rewardedVideo.setAdRequest(adRequest);	 	rewardedVideo.setAdRequest(adRequest);
    rewardedVideoAd.load();

    rewardedVideoAd.load();

  • Once ad is loaded, the event onLoadSuccess is called, set dynamic usr id (if needed) and show ads:

    Once ad is loaded, the event onLoadSuccess is called, set dynamic usr id (if needed) and show ads:

    YouAPPi.getInstance().setDynamicUserId("best_user_ever");	 	
    YouAPPi.getInstance().setDynamicUserId("best_user_ever");
    rewardedVideoAd.show();

    rewardedVideoAd.show();

  • Ad availability can also be checked by calling:

    Ad availability can also be checked by calling:

    rewardedVideoAd.isAvailable();
    rewardedVideoAd.isAvailable();

    If you’re using proguard in your application the following entries should be added to your proguard file: If you’re using proguard in your application the following entries should be added to your proguard file:

    -keep class com.google.gson.**{ *;}	 	
    -keep class com.google.gson.**{ *;}
    -keep class com.google.android.gms.**{*;}	 	-keep class com.google.android.gms.**{*;}
    -keep class com.youappi.sdk.**{*;}	 	-keep class com.youappi.sdk.**{*;}
    -keep interface com.youappi.sdk.**{*;}	 	-keep interface com.youappi.sdk.**{*;}
    -keep enum com.youappi.sdk.**{*;}	 	-keep enum com.youappi.sdk.**{*;}
    -keepclassmembers class * {	 	-keepclassmembers class * {
       @android.webkit.JavascriptInterface <methods>;	 	   @android.webkit.JavascriptInterface <methods>;
    }

    }

  • Android App Bundle

    Android App Bundle

    In order to upload your app’s compiled code and resources to Google Play using Android App Bundle without generating APK, exclude Android Manifest from the package options of your build.gradle: In order to upload your app’s compiled code and resources to Google Play using Android App Bundle without generating APK, exclude Android Manifest from the package options of your build.gradle:

    packagingOptions {	 	
    packagingOptions {
     exclude 'AndroidManifest.xml'	 	 exclude 'AndroidManifest.xml'
    }

    }

    User’s Private Information

    User’s Private Information

    For providing more relevant ads according to user’s interests YouAppi collects user’s installed packages information. By default, the user’s explicit consent flag value is ‘false’. By choosing ‘true’ you allow YouAppi to collect this information which helps us to optimise yield and raise eCPM. Make sure to post a privacy policy in both the designated field in the Play Developer Console and from within the Play distributed app itself to avoid violation of Google’s Developer Distribution Agreement. For providing more relevant ads according to user’s interests YouAppi collects user’s installed packages information. By default, the user’s explicit consent flag value is ‘false’. By choosing ‘true’ you allow YouAppi to collect this information which helps us to optimise yield and raise eCPM. Make sure to post a privacy policy in both the designated field in the Play Developer Console and from within the Play distributed app itself to avoid violation of Google’s Developer Distribution Agreement.
    User’s explicit consent can be set the following way: User’s explicit consent can be set the following way:

    YouAPPi.getInstance().sendApps(true);
    YouAPPi.getInstance().sendApps(true);

    GDPR User’s Consent

    GDPR User’s Consent

    The userConsent flag value should be determined by the app developer according to the User’s response to a Consent Request and according to the user being subject to the GDPR rules (e.g.: an EU residence). The userConsent flag value signals to YouAppi the permission to process and store the user’s Personal Information (e.g.: Advertising ID and IP address). In case that the flag value is false, YouAppi may decide not to respond to the ad request, since the user cannot be detected and his actions cannot be attributed to the user and hence also to YouAppi and to the app developer. The userConsent flag value should be determined by the app developer according to the User’s response to a Consent Request and according to the user being subject to the GDPR rules (e.g.: an EU residence). The userConsent flag value signals to YouAppi the permission to process and store the user’s Personal Information (e.g.: Advertising ID and IP address). In case that the flag value is false, YouAppi may decide not to respond to the ad request, since the user cannot be detected and his actions cannot be attributed to the user and hence also to YouAppi and to the app developer.
    GDPR user consent can be passed in the following ways: GDPR user consent can be passed in the following ways:

    YouAPPi.init(context, "<YOUR_APP_TOKEN>", userConsent);
    YouAPPi.init(context, "<YOUR_APP_TOKEN>", userConsent);
    YouAPPi.getInstance().setUserConsent(userConsent);
    YouAPPi.getInstance().setUserConsent(true);
    YouAPPi.getInstance().setAgeRestrictedUser(ageRestrictedUser);
    YouAPPi.getInstance().setAgeRestrictedUser(true);

    Logging and troubleshooting

    Logging and troubleshooting

    After initializing the SDK you can set LogListener to get detailed log events from YouAppi’s SDK: After initializing the SDK you can set LogListener to get detailed log events from YouAppi’s SDK:

    YouAPPi.getInstance().setLogListener(new Logger.LogListener()	 	
    YouAPPi.getInstance().setLogListener(new Logger.LogListener()
       {	 	   {
           @Override	 	       @Override
           public void log(String tag, String message)	 	       public void log(String tag, String message)
           {	 	       {
               // This will be called each time YouAppi SDK generates a log message.	 	           // This will be called each time YouAppi SDK generates a log message.
           }	 	       }
       });

    });

    Load and Show best practices

    Load and Show best practices

    Demo App

    Demo App

    A demo app showing a simple usage of the SDK can be found in the following Github repository: A demo app showing a simple usage of the SDK can be found in the following Github repository:
    https://github.com/YouAppi/youappi-sdk-android-demo https://github.com/YouAppi/youappi-sdk-android-demo
    The demo app contains 4 modules: The demo app contains 4 modules:

    Please make sure to read the README.md file for further instructions. Please make sure to read the README.md file for further instructions.