我想为我的 Java Android 应用展示 Unity 横幅广告 (Unity ads 3.0.0)。
我已阅读https://unityads.unity3d.com/help/android/integration-guide-android
根据指南,必须添加以下代码才能获得横幅广告。
public class UnityBannerExample extends Activity {
private View bannerView;
private Button bannerButton;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.unityads_example_layout);
final Activity myActivity = this;
final IUnityBannerListener unityBannerListener = new UnityBannerListener ();
final IUnityMonetizationListener unityMonetizationListener = new UnityMonetizationListener ();
UnityBanners.setBannerListener (unityBannerListener);
bannerButton = (Button) findViewById (R.id.unityads_example_banner_button);
bannerButton.setEnabled (true);
bannerButton.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick (View v) {
if (bannerView == null) {
UnityBanners.loadBanner (myActivity, "banner");
} else {
UnityBanners.destroy ();
}
}
});
final Button initializeButton = (Button) findViewById (R.id.unityads_example_initialize_button);
initializeButton.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick (View v) {
UnityMonetization.initialize (myActivity, "1234567", unityMonetizationListener, true);
}
});
}
private class UnityBannerListener implements IUnityBannerListener {
@Override
public void onUnityBannerLoaded (String placementId, View view) {
bannerView = view;
((ViewGroup) findViewById (R.id.unityads_example_layout_root)).addView (view);
}
@Override
public void onUnityBannerUnloaded (String placementId) {
bannerView = null;
}
@Override
public void onUnityBannerShow (String placementId) {
}
@Override
public void onUnityBannerClick (String placementId) {
}
@Override
public void onUnityBannerHide (String placementId) {
}
@Override
public void onUnityBannerError (String message) {
}
}
private class UnityMonetizationListener implements IUnityMonetizationListener {
@Override
public void onPlacementContentReady (String placementId, PlacementContent placementContent) {
}
@Override
public void onPlacementContentStateChange (String placementId, PlacementContent placementContent, UnityMonetization.PlacementContentState previousState, UnityMonetization.PlacementContentState newState) {
}
@Override
public void onUnityServicesError (UnityServices.UnityServicesError error, String message) {
}
}
}
有两个按钮bannerButton 和initializeButton。但我不想向用户显示按钮来初始化和显示横幅广告。我想在活动的 on start 方法中显示广告。
在没有bannerButton 和initializeButton 的情况下显示横幅广告的正确方法是什么。