开始集成

须知

  • Android 4.0 (Ice Cream Sandwich - API version 14 and above
  • Amazon OS 5.4 and above
  • In-Feed and MREC ads require API version 16 and above

集成SDK

请在Maven集成和Jar集成二选其一使用。建议使用Gradle Maven库形式集成

Maven集成

在 project-level build.gradle, 添加 maven URL:

allprojects {
  repositories {
    jcenter()
  }
}

在 app-level build.gradle 添加如下依赖:


dependencies { 
  // Vungle SDK
  implementation 'com.vungle:publisher-sdk-android:6.4.11'

  // Either appcompat-v7 or support-v4 is need for SDK operation 
  implementation 'com.android.support:appcompat-v7:28.0.0'  // Either
  implementation 'com.android.support:support-v4:27.1.1'    // Or

  // Recommended for SDK to be able to get Android Advertising ID
  implementation 'com.google.android.gms:play-services-basement:16.0.0'
  implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'
}

Jar集成


Screen_Shot_2019-07-10_at_8.23.20_AM.png

  1. 下载 SDK V6 , 解压缩放到工程libs文件夹下。 在 app-level build.gradle 添加如下依赖:
    dependencies {
        // Vungle SDK
      implementation files('libs/vungle-android-sdk-6.4.11.jar')
    
      // Required Third-party Dependencies
      implementation files('libs/converter-gson-2.5.0.jar')
      implementation files('libs/gson-2.8.2.jar')
      implementation files('libs/logging-interceptor-3.12.0.jar')
      implementation files('libs/okhttp-3.12.0.jar')
      implementation files('libs/okio-1.15.0.jar')
      implementation files('libs/retrofit-2.5.0.jar')
      implementation files('libs/VNG-moat-mobile-app-kit-2.5.1.jar') // Exclude when using AAR
    
      // Either appcompat-v7 or support-v4 is need for SDK operation 
      implementation 'com.android.support:appcompat-v7:28.0.0'  // Either
      implementation 'com.android.support:support-v4:27.1.1'    // Or
    
      // Recommended for SDK to be able to get Android Advertising ID
      implementation 'com.google.android.gms:play-services-basement:16.0.0'
      implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'
    }
    
    Note

注意

下载的Zip包中包含了aar和.jar文件,请使用其中之一即可。

  • 修改AndroidManifest.xml
    <!--Required Permissions-->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    <!--Recommended Permissions-->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
        
    <!--Vungle Activities-->
    <activity
      android:name="com.vungle.warren.ui.VungleActivity"
      android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
      android:launchMode="singleTop"
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
          
    <receiver
      android:name="com.vungle.warren.NetworkProviderReceiver"
      android:enabled="false" >
      <intent-filter>
        <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
    </receiver>

初始化Vungle SDK

在请求广告之前,请先初始化SDK。一般来说需要在App启动时立刻初始化。示例如下:

Vungle.init("YOUR_VUNGLE_APP_ID", getApplicationContext(), new InitCallback() {
    @Override
    public void onSuccess() {
        // Initialization has succeeded and SDK is ready to load an ad or play one if there
        // is one pre-cached already
    }

    @Override
    public void onError(Throwable throwable) {
        // Initialization error occurred - throwable.getLocalizedMessage() contains error message
    }

    @Override
    public void onAutoCacheAdAvailable(String placementId) {
        // Callback to notify when an ad becomes available for the cache optimized placement
        // NOTE: This callback works only for the cache optimized placement. Otherwise, please use
        // LoadAdCallback with loadAd API for loading placements.
    }
};

通过 isInitialized 方法来判断是否初始化成功:

boolean isInitialized = Vungle.isInitialized();

注意

Hardware Acceleration

Hardware acceleration Hardware acceleration是默认开启的。这个功能能帮助SDK正确的显示Dynamic Template和原生广告。请确保开启该功能

<application android:hardwareAccelerated="true" ...>

这篇文章有帮助吗?

Questions?

Need further assistance, feel free to reach out to us, we’re here to help!