Xamarin.forms 带有Xamarin.表单的横幅广告
我只是想知道Xamarin.Forms支持的横幅广告没有任何补丁或漏洞。是否有任何广告提供商向其SDK提供Xamarin.FormsXamarin.forms 带有Xamarin.表单的横幅广告,xamarin.forms,admob,ads,banner-ads,Xamarin.forms,Admob,Ads,Banner Ads,我只是想知道Xamarin.Forms支持的横幅广告没有任何补丁或漏洞。是否有任何广告提供商向其SDK提供Xamarin.Forms 提前感谢。这里有Xamarin.Android的SDK和分步示例。你需要裸体 我用它在谷歌Play发布的Xamarin.Forms应用程序中显示广告 以下是应用程序android部分的示例代码: using System; using Android.App; using Android.Content; using Android.Runtime; using
提前感谢。这里有Xamarin.Android的SDK和分步示例。你需要裸体 我用它在谷歌Play发布的Xamarin.Forms应用程序中显示广告 以下是应用程序android部分的示例代码:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Support.V7.App;
using Android.Gms.Ads;
using Android;
namespace AdMobExample
{
[Activity (Label = "@string/app_name", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected AdView mAdView;
protected InterstitialAd mInterstitialAd;
protected Button mLoadInterstitialButton;
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
SetContentView (Resource.Layout.activity_main);
mAdView = FindViewById<AdView> (Resource.Id.adView);
var adRequest = new AdRequest.Builder ().Build ();
mAdView.LoadAd (adRequest);
mInterstitialAd = new InterstitialAd (this);
mInterstitialAd.AdUnitId = GetString (Resource.String.test_interstitial_ad_unit_id);
mInterstitialAd.AdListener = new AdListener (this);
mLoadInterstitialButton = FindViewById<Button> (Resource.Id.load_interstitial_button);
mLoadInterstitialButton.SetOnClickListener (new OnClickListener (this));
}
protected void RequestNewInterstitial ()
{
var adRequest = new AdRequest.Builder ().Build ();
mInterstitialAd.LoadAd (adRequest);
}
protected void BeginSecondActivity ()
{
var intent = new Intent (this, typeof(SecondActivity));
StartActivity (intent);
}
protected override void OnPause ()
{
if (mAdView != null) {
mAdView.Pause ();
}
base.OnPause ();
}
protected override void OnResume ()
{
base.OnResume ();
if (mAdView != null) {
mAdView.Resume ();
}
if (!mInterstitialAd.IsLoaded) {
RequestNewInterstitial ();
}
}
protected override void OnDestroy ()
{
if (mAdView != null) {
mAdView.Destroy ();
}
base.OnDestroy ();
}
class AdListener : Android.Gms.Ads.AdListener
{
MainActivity that;
public AdListener (MainActivity t)
{
that = t;
}
public override void OnAdClosed ()
{
that.RequestNewInterstitial ();
that.BeginSecondActivity ();
}
}
class OnClickListener : Java.Lang.Object, View.IOnClickListener
{
MainActivity that;
public OnClickListener (MainActivity t)
{
that = t;
}
public void OnClick (View v)
{
if (that.mInterstitialAd.IsLoaded) {
that.mInterstitialAd.Show ();
} else {
that.BeginSecondActivity ();
}
}
}
}
}
使用系统;
使用Android.App;
使用Android.Content;
使用Android.Runtime;
使用Android.Views;
使用Android.Widget;
使用Android.OS;
使用Android.Support.V7.App;
使用Android.Gms.Ads;
使用安卓系统;
名称空间admobe示例
{
[活动(Label=“@string/app_name”,MainLauncher=true)]
公共类MainActivity:AppCompativeActivity
{
受保护的AdView mAdView;
受保护的间质和间质;
受保护按钮MLOAD中间按钮;
创建时受保护的覆盖无效(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
mAdView=FindViewById:
使用Google.MobileAds;
...
常量字符串interstitilid=“”;
间质组织;
公共覆盖无效ViewDidLoad()
{
base.ViewDidLoad();
createandrequestinterstital();
}
公众假期过后()
{
如果(数据已准备就绪)
ADINTERSTIAL.PresentFromRootViewController(导航控制器);
}
void CreateAndRequestInterstitial()
{
a间质=新间质(间质);
adInterstital.Screen+=(发件人,e)=>{
//Interstitual是一次性使用的对象。这意味着一旦显示Interstitual,就会使用它
//返回true,并且该间隙不能用于加载另一个ad。
//要请求另一个间隙,您需要创建一个新的间隙对象。
adinterstital.Dispose();
adInterstitial=null;
createandrequestinterstital();
};
var request=request.GetDefaultRequest();
//在指定的设备上请求测试广告。当
//发出广告请求。GadBanerView在服务器上运行时自动返回测试广告
//模拟器。获取设备ID后,将其添加到此处
request.TestDevices=new[]{request.SimulatorId.ToString()};
adInterstitial.LoadRequest(请求);
}
它会在所有页面中显示广告,还是只引用MainActivity?@ChandreshKhambhayata您确实需要自己完成代码。这是一个示例代码,非常简单。它不适合盲拷贝粘贴。当屏幕方向改变时,您是否遇到过问题?目前在iOS上,只要设备翻转,都会出现问题从纵向到横向或反向,广告消失,我假设它离开屏幕或大小弄乱或其他什么,但我无法理解。尝试使用智能横幅,顺便说一句。翻转设备时,我没有发现全屏广告有问题。你处理过调整大小的事件吗?
using Google.MobileAds;
...
const string intersitialId = "<Get your ID at google.com/ads/admob>";
Interstitial adInterstitial;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
CreateAndRequestInterstitial ();
}
public void AfterSomeTime ()
{
if (adInterstitial.IsReady)
adInterstitial.PresentFromRootViewController (navController);
}
void CreateAndRequestInterstitial ()
{
adInterstitial = new Interstitial (intersitialId);
adInterstitial.ScreenDismissed += (sender, e) => {
// Interstitial is a one time use object. That means once an interstitial is shown, HasBeenUsed
// returns true and the interstitial can't be used to load another ad.
// To request another interstitial, you'll need to create a new Interstitial object.
adInterstitial.Dispose ();
adInterstitial = null;
CreateAndRequestInterstitial ();
};
var request = Request.GetDefaultRequest ();
// Requests test ads on devices you specify. Your test device ID is printed to the console when
// an ad request is made. GADBannerView automatically returns test ads when running on a
// simulator. After you get your device ID, add it here
request.TestDevices = new [] { Request.SimulatorId.ToString () };
adInterstitial.LoadRequest (request);
}