集成Vungle SDK Android/Amazon

开始之前

Vungle SDK已经在API 30 Android 11上测试通过。

要求

  • Android 5.0 (API version 21) 或更高版本
  • Amazon OS 5.4 or higher
  • 您的平台需要使用AndroidX并使用Android SDK 6.5及以上版本。
  • 集成需要一个Vungle帐户 ,请在该帐户中创建一个新的Android 或 Amazon应用。请参阅我们的使用发布者仪表板文章中的添加您的应用和展示位置部分,以了解如何在Vungle Dashboard中设置广告位。

下载SDK

下载 Vungle SDK for Android or Amazon.

Reference: Sample App and Java Doc

示例应用: 请参考示例应用来集成您的应用 https://github.com/Vungle/Android-SDK.

JavaDoc: https://vungle.github.io/vungle-android-sdk/javadoc.

步骤 1. 将Vungle SDK添加到您的项目中

您可以使用 Gradle 或使用 JAR or AAR 的方式来集成Vungle SDK。

// API version compatibility
minSdkVersion 21
compileSdkVersion 30
targetSdkVersion 30

Gradle

打开项目级别的 build.gradle,并在“all projects”部分添加 Maven URL。
allprojects {
  repositories {
    mavenCentral()
  }
}
打开应用程序级别的 build.gradle 文件,并在“dependencies”部分添加其他依赖项。
dependencies { 
  // Vungle SDK
  implementation 'com.vungle:publisher-sdk-android:6.10.1'
 
  implementation 'androidx.core:core:1.3.2'
  implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'

  // When appcompat is being used, core and localbroadcastmanager are the dependencies
  // that is getting included
  // implementation 'androidx.appcompat:appcompat:1.2.0'

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

JAR

  1. 下载Vungle SDK 并解压,然后前往 libs 文件夹,复制所有的 .jar 文件并将其添加到您的项目工程的 libs 文件件:
    • vungle-android-sdk-6.10.1.jar
    • gson-2.8.6.jar
    • okhttp-3.12.12.jar
    • okio-1.15.0.jar
  2. 打开应用程序级别的 build.gradle 文件,并在“dependencies”部分添加其他依赖项。

    dependencies {
      // Vungle SDK
      implementation files('libs/vungle-android-sdk-6.10.1.jar')
    
      // Required Third-party Dependencies
      implementation files('libs/gson-2.8.6.jar')
      implementation files('libs/okhttp-3.12.12.jar')
      implementation files('libs/okio-1.15.0.jar')
    
      implementation 'androidx.core:core:1.6.0'
      implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
    
      // When appcompat is being used, core and localbroadcastmanager are the dependencies
      // that is getting included
      // implementation 'androidx.appcompat:appcompat:1.3.0'
    
      // Recommended for SDK to be able to get Android Advertising ID
      implementation 'com.google.android.gms:play-services-basement:17.6.0'
      implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
    }
  3. 更新以下内容到您的AndroidManifest.xml文件中。
    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="30" />
    
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    <application
        android:hardwareAccelerated="true"
        android:supportsRtl="true" >
        <activity
            android:name="com.vungle.warren.ui.VungleActivity"
            android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
            android:launchMode="singleTop"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
    
        <provider
            android:name="com.vungle.warren.utility.VungleProvider"
            android:authorities="${applicationId}.vungle-provider"
            android:exported="false" />
    </application>

AAR

  1. 下载 SDK 并解压,然后前往libs 文件夹,复制SDK .aar 和所有 .jar 并添加到您的 libs 文件夹中:
    • vungle-android-sdk-6.10.1.aar
    • gson-2.8.6.jar
    • okhttp-3.12.12.jar
    • okio-1.15.0.jar
  2. 打开应用程序级别的 build.gradle 文件,并在“dependencies”部分添加其他依赖项。

    dependencies {
      // Vungle SDK
      implementation files('libs/vungle-android-sdk-6.10.1.aar')
    
      // Required Third-party Dependencies
      implementation files('libs/gson-2.8.6.jar')
      implementation files('libs/okhttp-3.12.12.jar')
      implementation files('libs/okio-1.15.0.jar')
    
      implementation 'androidx.core:core:1.6.0'
      implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
    
      // When appcompat is being used, core and localbroadcastmanager are the dependencies
      // that is getting included
      // implementation 'androidx.appcompat:appcompat:1.3.0'
    
      // Recommended for SDK to be able to get Android Advertising ID
      implementation 'com.google.android.gms:play-services-basement:17.6.0'
      implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
    }

步骤 2:导入 Vungle SDK

import com.vungle.warren.Vungle;
import com.vungle.warren.AdConfig;              // Custom ad configurations
import com.vungle.warren.InitCallback;          // Initialization callback
import com.vungle.warren.LoadAdCallback;        // Load ad callback
import com.vungle.warren.PlayAdCallback;        // Play ad callback
import com.vungle.warren.VungleNativeAd;        // MREC ad
import com.vungle.warren.Banners;               // Banner ad
import com.vungle.warren.VungleBanner;          // Banner ad
import com.vungle.warren.Vungle.Consent;        // GDPR consent
import com.vungle.warren.VungleSettings         // Minimum disk space
import com.vungle.warren.error.VungleException  // onError message

步骤3.添加代码

初始化 SDK

init 初始化时 使用 VungleSettings
public static void init(@NonNull final String appId,
                        @NonNull final Context context,
                        @NonNull final InitCallback callback)

初始化方法采用以下参数:

  • Vungle application ID
  • 应用程序上下文
  • InitCallback
    • onSuccess: notifies when the SDK has successfully initialized
    • onError: notifies when the initialization has failed
      • Throws IllegalArgumentException if InitCallback is null.
    • onAutoCacheAdAvailable: notifies when the auto-cached placement has an ad available to play
  • VungleSettings (optional)
6.5.0 & above Legacy
Vungle.init(appId, getApplicationContext(), new InitCallback() {
  @Override
  public void onSuccess() {
    // SDK has successfully initialized
  }

  @Override
  public void onError(VungleException exception) {
    // SDK has failed to initialize
  }

  @Override
  public void onAutoCacheAdAvailable(String placementId) {
    // Ad has become available to play for a cache optimized placement
  }
};
Overridable Methods 描述
onSuccess() 当SDK初始化成功时触发,此时可以开始请求广告或播放广告
onError(VungleException exception) 当初始化失败时触发,此时请查看错误信息getLocalizedMessage以便获知getExceptionCode
onAutoCacheAdAvailable(String placementId) 当广告缓存好时触发。

您可以随时通过调用 isInitialized 方法来检查 Vungle SDK 是否已初始化:

public static boolean isInitialized()

Integrate Ad Formats

根据文档来集成各种广告格式:

更多定制广告

请查看 Advanced Settings 来完成您需要的SDK设置,例如GDPR, CCPA 和其他设置。

 

Powered by Creativity Driven by Performance Sign Up Here

Questions?

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

这篇文章有帮助吗?