- Copy the
InMobi-5.x.x
JAR file and place it in the/libs
folder in your project (you may have to create the directory if it doesn't already exist). Make sure the IDE's UI reflects this change. If you are using Android Studio, right click on your project and add to library. - If you have a ProGuard configuration file, add the below ProGuard configuration to it
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient{ public *; } -keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info{ public *; } -keep class com.inmobi.** { *; } -dontwarn com.inmobi.**
- Also, ensure that you have the latest version of the Google Play Services SDK installed and include it in your project by adding a new build rule under dependencies (in your build.gradle file) for the latest version of play-services, if on Android Studio. Please see herefor more information. For example:
- dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
}
- dependencies {
Add the following lines to your AndroidManifest.xml
file.
Add the following before the closing </manifest>
tag.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--Recommended permissions to receive brand‐centric ads with interactive functionality for better eCPMs-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
Add the following before the closing </application>
tag in your AndroidManifest.xml
file.
<!--Required Activity for rendering ads in the embedded browser-->
<activity android:name="com.inmobi.rendering.InMobiAdActivity"
android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:hardwareAccelerated="true" />
<!--Required Receiver for enhanced targeting for better ads.-->
<receiver android:name="com.inmobi.commons.core.utilities.uid.ImIdShareBroadCastReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="com.inmobi.share.id" />
</intent-filter>
</receiver>
<service android:enabled="true" android:name="com.inmobi.signals.activityrecognition.ActivityRecognitionManager" />
<!--Required for Google Play Services-->
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
- Import the
com.inmobi.ads
,com.inmobi.sdk
&java.util.Map
package in your activity, typically in the import section of your main activity file.import java.util.Map; import com.inmobi.ads.*; import com.inmobi.sdk.*;
CopyCopied to clipboard -
The account ID is your app’s unique identifier. Use the account ID when integrating with the InMobi SDK.
Important: You must initialize the SDK at app launch. The initialize API must be invoked on the UI Thread, in the onCreate method of the launcher activity.
Initialization needs to be done only once per app, irrespective of the number of placements.
Your account ID has been prepopulated to aid copying and pasting.
InMobiSdk.init(this, "9697f54927be4ff3ba71a02181323d65"); //'this' is used specify context
InMobi serves both landscape and portrait type of interstitial ads (non-rewarded video, images, rich-media). The InMobi SDK will automatically ensure that it serves appropriate ads as per the application orientation.
The <code>InMobiInterstitial</code> class is used to request interstitial ads. Perform the below steps to implement an interstitial ad
- Create an
InMobiInterstitial
instance and call load to prefetch the ad. Copy and paste the below in your app, typically at a section that is called each time a new session has started.// ‘this’ is used to specify context, replace it with the appropriate context as needed. InMobiInterstitial interstitial = new InMobiInterstitial(this, 1452964422388L, new InMobiInterstitial.InterstitialAdListener() { @Override public void onAdRewardActionCompleted(InMobiInterstitial ad, Map rewards) {} @Override public void onAdDisplayed(InMobiInterstitial ad) {} @Override public void onAdDismissed(InMobiInterstitial ad) {} @Override public void onAdInteraction(InMobiInterstitial ad, Map params) {} @Override public void onAdLoadSucceeded(final InMobiInterstitial ad) {} @Override public void onAdLoadFailed(InMobiInterstitial ad, InMobiAdRequestStatus requestStatus) {} @Override public void onUserLeftApplication(InMobiInterstitial ad){} }); interstitial.load();
CopyCopied to clipboard - Show the ad at the desired placement in your app. This could be after a life has lost, a level cleared, and so on by using the below snippet
if(interstitial.isReady()) interstitial.show();
CopyCopied to clipboardNote: If you want to refresh the interstitial ad, invoke the
load()
method again before making a call toshow()
. Make sure that the current state of the interstitial ad isready
before making the call. Otherwise, no ad will be shown and a log message stating the error condition will be printed.