Android InApp Documentation - yanivav/Documentation GitHub Wiki

**Last version: 2.4.11**

NOTES:

  • The code samples in this document can be copy/pasted into your source code
  • Please notice that steps 1-3 are mandatory
  • If you have any questions, contact us via [email protected]


##Step 1, Adding the SDK JAR to Your Eclipse Project

IMPORTANT: This is a mandatory step

Copy the StartAppInApp-x.x.x.jar file from the SDK zip to the “libs” directory of your project.

Back to top

##Step 2, Updating Your AndroidManifest.xml File > **IMPORTANT:** This is a mandatory step

####Permissions Under the main <manifest> element, add the following permissions.

Mandatory Permissions:

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

Optional Permissions (allow StartApp to show higher eCPM Geo-targeted ads):

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

####Activities Under the <application> element, add the following activities:

<activity android:name="com.startapp.android.publish.list3d.List3DActivity"
          android:theme="@android:style/Theme" />

<activity android:name="com.startapp.android.publish.AppWallActivity"
          android:theme="@android:style/Theme.Translucent"
          android:configChanges="orientation|keyboardHidden|screenSize" />

Back to top

##Step 3, Initialization > **IMPORTANT:** > - This is a mandatory step

In your main activity, go to the OnCreate method and before calling setContentView() call the static function:

StartAppSDK.init(this, "Your Developer Id", "Your App ID", true);

Replace "Your Developer Id" and "Your App ID" with your own values provided in the developers’ portal.
After logging in, your developer ID will be at the top right-hand corner of the page:

To find your application ID, click on the at the top of the main screen and then choose the relevant ID from your app list:

The last true parameter enables the "Return Ads" feature as explained in the next section. If you want to disable this feature, simply pass false instead.

Back to top

##Return Ads The **Return Ad** is a new ad unit which is displayed once the user returns to your application after a certain period of time. To minimize the intrusiveness, short time periods are ignored. For example, the Return Ad won't be displayed if the user leaves your application to take a short phone call before returning).

Return ads are enabled and activated by default. If you want to disable this feature, simply pass "false" as the 4th parameter of the StartAppSDK.init method:

StartAppSDK.init(this, "Your Developer Id", "Your App ID", false);

Back to top

##Showing Banners Add the following View inside your Activity layout XML: ```java ```

NOTE: This code places a View inside your Activity. You also have the option to add additional attributes for placing it in the desired location in your Activity.

If you wish to add a specific type of banner, please refer to the Advanced Usage.

Back to top

##Showing Interstitial Ads Interstitial Ads are full screen ads (either static, animation, or video) that are displayed before or after a certain content page or action, such as upon entering a stage, between stages, while waiting for an action, upon exiting the application and more. Interstitial Ads are orientation-sensitive and will be displayed automatically as per the application orientation.

####Initializing the StartApp Ad Object 1. In your Activity, create a member variable, as follows:

private StartAppAd startAppAd = new StartAppAd(this);

2. Override the onResume() method and add the method startAppAd.onResume() AFTER the method super.onResume():

@Override
public void onResume() {
    super.onResume();
    startAppAd.onResume();
}

3. Override the onPause() method and add the method startAppAd.onPause() AFTER the method super.onPause():

@Override
public void onPause() {
    super.onPause();
    startAppAd.onPause();
}

####Showing Exit Ads Add the following code to show an ad upon exiting your application.

To show an ad when pressing the 'Back' button, override the onBackPressed() method and add the method startAppAd.onBackPressed() BEFORE the method super.onBackPressed():

@Override
public void onBackPressed() {
    startAppAd.onBackPressed();
    super.onBackPressed();
}

####Showing Interstitials Add the following code to the appropriate place(s) in the activity in which you would like to show the Ad:

startAppAd.showAd(); // show the ad
startAppAd.loadAd(); // load the next ad

NOTE: loadAd() must be called immediately after showAd(). This will load the next Ad.

The following is an example of showing an Interstitial Ad between Activities:

public void btnOpenActivity (View view){
    Intent nextActivity = new Intent(this, NextActivity.class);
    startActivity(nextActivity);
    startAppAd.showAd();
    startAppAd.loadAd();
}

####Showing Rewarded Video Ads Rewarded Ads are interstitial video ads that provide a reward to the user in exchange for watching an entire video ad. The reward might be in-app goods, virtual currency or any premium content provided by the application. Because users actually opt-in to watch a rewarded video and are granted with something valuable in return, Rewarded Ads are an effective and clean monetization solution for gaining a stronger retention and keeping your users for a longer time in the application.

In order to show a Rewarded Ad, pass the following AdMode parameter when calling the loadAd() method:

startAppAd.loadAd(AdMode.REWARDED_VIDEO);

Implement the following listener in order to get a callback when the user completes watching the video and is eligible for getting the reward:

startAppAd.setVideoListener(new VideoListener() {
     @Override
     public void onVideoCompleted() {
          // Grant user with the reward
     }
});

IMPORTANT: loading an ad might take a few seconds especially in case of a video, so it's important not to show the ad immediately after loading it. In case you call showAd() while the ad hasn't been successfully loaded yet, nothing will be displayed. It is recommended to use the "onReceiveAd" callback which is triggered when an ad was loaded and ready to use (see Adding a Callback when an Interstitial Ad is loaded).

Back to top

##Showing a Splash Ad A Splash Ad is a full-page ad that is displayed immediately after the application is launched. A Splash Ad first displays a full page splash screen that you define (as described below) followed by a full page ad. StartApp In-Ad provides two modes for displaying Splash screens:
Splash Screen Mode Description
Template Mode StartApp In-Ad provides a pre-defined template in which you can place your own creatives, such as application name, logo and loading animation.
User-Defined Mode Please refer to the Advanced Usage

####Adding the Splash Screen In the OnCreate method of your Activity, after calling StartAppAd.init and before setContentView, call the following static function:

StartAppAd.showSplash(this, savedInstanceState);

Apply the following parameters:

  • this: The context (Activity)
  • savedInstanceState: The Bundle parameter passed to your onCreate(Bundle savedInstanceState) method

If you wish to customize or use a different splash screen, please refer to the Advanced Usage.

Back to top

##Integrating the Slider After calling ```setContentView()```, in the ```OnCreate()``` method of your main activity, call the static function: ```java StartAppAd.showSlider(this); ```

If you would like the Slider to appear in additional activities, repeat this step in each one of the activities you would like it to show in. The Slider cannot be implemented in activities with a Dialog Theme: (android:theme="@android:style/Theme.Dialog")

NOTE: for better user experience, and in order to avoid reload of the Slider when rotating the phone, it is recommended to go back to your manifest file and add the following attribute to any <activity> element that you added the Slider to: android:configChanges="orientation|screenSize"

Back to top

##Obfuscation (Optional) Obfuscation protects an application from reverse-engineering or modification by making it harder for a third-party to access your source (decompiled) code.

StartApp In-Ad is already obfuscated! Therefore, if you did not obfuscate your application using ProGuard™, then you can skip this step. If you have obfuscated your application using ProGuard, then use the following in the ProGuard configuration file:

-keep class com.startapp.** {
      *;
}

-keepattributes Exceptions, InnerClasses, Signature, Deprecated, SourceFile,
LineNumberTable, *Annotation*, EnclosingMethod
-dontwarn android.webkit.JavascriptInterface
-dontwarn com.startapp.**

Back to top

##Native Ads A "Native Ad" is a raw representation of an ad without any pre-defined wrapping UI, which gives you the freedom to design and control the ad exactly as you want. Using Native Ads, you can design an ad experience that perfectly fits your application's scene, content and functionality.

For a full integration guide, please refer to the "Using Native Ads" section under the "Advanced Usage" page.


Back to top

##Enjoy Higher eCPM with Demographic-Targeted Ads If you know your user's gender or age, StartApp can use it to serve better-targeted ads which can increase your eCPM and revenue significantly.

####Set Age and Gender Upon initialization, after providing your DevId and AppId, pass the SDKAdPreferences object with its data:

StartAppSDK.init(this, 
                 "Your Developer Id", 
                 "Your App ID", 
                 new SDKAdPreferences()
                      .setAge(35)
                      .setGender(Gender.FEMALE));
}
  • setAge can take an integer.
  • setGender can take one of the following values: Gender.FEMALE or Gender.MALE.

####Set Location The location of the user is a dynamic property which is changed constantly. Hence, you should provide it every time you load a new Ad:

@Override
public void onResume() {
    super.onResume();
    startAppAd.loadAd(new AdPreferences()
                           .setLatitude(31.776719)
                           .setLongitude(35.234508));
    startAppAd.onResume();
}

In your onResume() method, use the AdPreferences object instead of just calling startAppAd.onResume() as described above. Do the same for each loadAd() call in your project.

Back to top

##Sample Project StartApp provides a sample integration project available on [GitHub](https://github.com/StartApp-SDK/StartApp_InApp_SDK_Example)

Back to top

##Advanced Usage For advanced usage, please refer to the ["Advanced Usage"](android-advanced-usage)

Back to top

##SearchBox SDK Removal Procedure If you are upgrading from our old SearchBox SDK, please refer to the ["SearchBox SDK Removal Procedure"](SearchBox-SDK-Removal-Procedure).

Back to top

⚠️ **GitHub.com Fallback** ⚠️