Android에서 인터스티셜 광고 구현
전체 화면 인터스티셜 광고를 표시하려면 UnityAds
API를 사용합니다.
인터스티셜 광고 예시
이 예시에서는 Unity Ads가 성공적으로 초기화되기만 하면 게임 내 어느 곳에서나 DisplayInterstitialAd
를 호출하여 인터스티셜 광고를 표시할 수 있습니다.
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.unity3d.ads.IUnityAdsLoadListener;
import com.unity3d.ads.IUnityAdsShowListener;
import com.unity3d.ads.UnityAdsShowOptions;
import com.unity3d.ads.example.R;
import com.unity3d.ads.IUnityAdsInitializationListener;
import com.unity3d.ads.UnityAds;
public class ShowInterstitialAd extends AppCompatActivity implements IUnityAdsInitializationListener {
private String unityGameID = "1234567";
private Boolean testMode = true;
private String adUnitId = "video";
private IUnityAdsLoadListener loadListener = new IUnityAdsLoadListener() {
@Override
public void onUnityAdsAdLoaded(String placementId) {
UnityAds.show((Activity)getApplicationContext(), adUnitId, new UnityAdsShowOptions(), showListener);
}
@Override
public void onUnityAdsFailedToLoad(String placementId, UnityAds.UnityAdsLoadError error, String message) {
Log.e("UnityAdsExample", "Unity Ads failed to load ad for " + placementId + " with error: [" + error + "] " + message);
}
};
private IUnityAdsShowListener showListener = new IUnityAdsShowListener() {
@Override
public void onUnityAdsShowFailure(String placementId, UnityAds.UnityAdsShowError error, String message) {
Log.e("UnityAdsExample", "Unity Ads failed to show ad for " + placementId + " with error: [" + error + "] " + message);
}
@Override
public void onUnityAdsShowStart(String placementId) {
Log.v("UnityAdsExample", "onUnityAdsShowStart: " + placementId);
}
@Override
public void onUnityAdsShowClick(String placementId) {
Log.v("UnityAdsExample", "onUnityAdsShowClick: " + placementId);
}
@Override
public void onUnityAdsShowComplete(String placementId, UnityAds.UnityAdsShowCompletionState state) {
Log.v("UnityAdsExample", "onUnityAdsShowComplete: " + placementId);
}
};
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
// Initialize the SDK:
UnityAds.initialize(getApplicationContext(), unityGameID, testMode, this);
}
@Override
public void onInitializationComplete() {
DisplayInterstitialAd();
}
@Override
public void onInitializationFailed(UnityAds.UnityAdsInitializationError error, String message) {
Log.e("UnityAdsExample", "Unity Ads initialization failed with error: [" + error + "] " + message);
}
// Implement a function to load an interstitial ad. The ad will start to show after the ad has been loaded.
public void DisplayInterstitialAd () {
UnityAds.load(adUnitId, loadListener);
}
}
다음 단계: Android에서 보상형 광고 구현 기술 자료를 참조하여 구현 사항을 개선하십시오.