如何集成inmobi到android

3 篇文章 0 订阅
2 篇文章 0 订阅
Adding SDK to your project
  1. 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.
  2. If you have a ProGuard configuration file, add the below ProGuard configuration to it
    1. -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.**


  3. 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:
    1. dependencies {
        compile 'com.google.android.gms:play-services:7.5.0'
      }
Making Changes to your Manifest File

Add the following lines to your AndroidManifest.xml file.

Add the following before the closing </manifest> tag.

    <!--Mandatory permissions to receive ads-->
    <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"/>


Initializing the InMobi SDK
  • Import the com.inmobi.adscom.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.*;
       
       
    Copy
    Copied 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
Implementing a Full­ Screen Interstitial Ad

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

  1. Create an InMobiInterstitial instance and call load to pre­fetch 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();
       
       
    Copy
    Copied to clipboard
  2. 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();
       
       
    Copy
    Copied to clipboard

    Note: If you want to refresh the interstitial ad, invoke the load() method again before making a call to show(). Make sure that the current state of the interstitial ad is ready before making the call. Otherwise, no ad will be shown and a log message stating the error condition will be printed.


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值