[英]How to integrate banner ads of unity to flutter
I am trying to add banner ads to unity_ads_flutter plugin. 我正在尝试将横幅广告添加到unity_ads_flutter插件。 But where can I add banner view to activity? 但是我可以在哪里向活动添加横幅视图? Can anyone provide me some ideas and examples? 谁能给我一些想法和例子? The hard part is that I don't know how to integrate code in onUnityBannerLoaded(in the example) to flutter plugin. 困难的部分是我不知道如何将onUnityBannerLoaded(在示例中)中的代码集成到Flutter插件中。
This is a link to unity_ads_flutter plugin: https://github.com/EPNW/unity_ads_flutter This is a link to unity guide: https://unityads.unity3d.com/help/android/integration-guide-android#banner-ads 这是unity_ads_flutter插件的链接: https://github.com/EPNW/unity_ads_flutter这是统一指导的链接: https://unityads.unity3d.com/help/android/integration-guide-android#banner-ads
Example Code from unity guide: 统一指南中的示例代码:
public class UnityBannerExample extends Activity {
private String unityGameId = “1234567”;
private Bool testMode = true;
private String placementId = “banner”;
private View bannerView;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.unityads_example_layout);
final Activity myActivity = this;
// Declare a new banner listener, and set it as the active banner listener:
final IUnityBannerListener myBannerListener = new UnityBannerListener ();
UnityBanners.setBannerListener (myBannerListener);
// Initialize the Ads SDK:
UnityAds.initialize (this, unityGameID, myAdsListener, testMode);
}
// Implement a function to display or destroy a banner ad:
@Override
public void ToggleBannerAd () {
// If no banner exists, show one; otherwise remove the existing one:
if (bannerView == null) {
// Optionally specify the banner’s anchor position:
UnityBanners.setBannerPosition (BannerPosition.BOTTOM_CENTER);
// Request ad content for your Placement, and load the banner:
UnityBanners.loadBanner (myActivity, "banner");
} else {
UnityBanners.destroy ();
}
}
// Implement the banner listener interface methods:
private class UnityBannerListener implements IUnityBannerListener {
@Override
public void onUnityBannerLoaded (String placementId, View view) {
// When the banner content loads, add it to the view hierarchy:
bannerView = view;
((ViewGroup) findViewById (R.id.unityads_example_layout_root)).addView (view);
}
@Override
public void onUnityBannerUnloaded (String placementId) {
// When the banner’s no longer in use, remove it from the view hierarchy:
bannerView = null;
}
@Override
public void onUnityBannerShow (String placementId) {
// Called when the banner is first visible to the user.
}
@Override
public void onUnityBannerClick (String placementId) {
// Called when the banner is clicked.
}
@Override
public void onUnityBannerHide (String placementId) {
// Called when the banner is hidden from the user.
}
@Override
public void onUnityBannerError (String message) {
// Called when an error occurred, and the banner failed to load or show.
}
}
}
To be more clear, I want to ask how to add the view returned from onUnityBannerLoaded 更清楚地说,我想问一下如何添加从onUnityBannerLoaded返回的视图
We have the same issue. 我们有同样的问题。 You can follow our evolution of the plugin here: FlutterUnityAds . 您可以在此处关注我们插件的演变: FlutterUnityAds 。
We also asked to the Reddit Flutter Community if someone can help us: Reddit discussion 我们还询问了Reddit Flutter社区是否有人可以帮助我们: Reddit讨论
Hope we'll get some answers. 希望我们能得到一些答案。 Please, tell us if you find how to solve that problem. 请告诉我们您是否找到解决该问题的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.