我正在尝试通过官方博客上的教程将Ad Mob与xamarin android集成。它可以正常使用虚拟ID,但不适用于我的广告单元ID。
这是我的MainActivity.cs
public class MainActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var id = "ca-app-pub-*******************";
Android.Gms.Ads.MobileAds.Initialize(ApplicationContext, id);
var adView = FindViewById<AdView>(Resource.Id.adView);
var adRequest = new AdRequest.Builder().Build();
adView.LoadAd(adRequest);
}
}
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_ad_unit_id" />
</LinearLayout>
的strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">App2</string>
<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string> <!--this works-->
<!--<string name="banner_ad_unit_id">ca-app-pub-
6656166334594340/1253040688</string>--> <!--this dont-->
</resources>
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="App2.App2" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:allowBackup="true" android:label="@string/app_name">
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
</manifest>