如何整合在最新的Andr​​oid MonoGame(新华社)AdMob的广告?新华社、广告、最新、Andr

2023-09-09 22:01:26 作者:△ 三分流氓气 ▌▎

我已经花了几天时间研究AdMob的整合MonoGame Android和到目前为止还没有能够锦旗成功添加到我刚才提出的游戏。 所有我到目前为止发现问题的答案是非常过时的,没有我发现的例子都工作在最新的Andr​​oid的API。

I have spent the last couple days researching AdMob integration for MonoGame Android and so far have not been able to successfully add a banner to the game I just made. All of the answers I have found so far are terribly outdated and none of the examples I found are working in the latest Android APIs.

我在Visual Studio中使用MonoGame 3.2开发版本#983。

I am using development build #983 of MonoGame 3.2 in Visual Studio.

我曾尝试:

使用本GitHub库中找到的示例:/ CartBlanche / MonoGame采样/树/主/ AdMob的

using the sample found in this github repo: /CartBlanche/MonoGame-Samples/tree/master/AdMob

,以及在这个GitHub库中的示例:/ xamarin / monodroid采样/树/主/ AdMob的

as well as the sample found in this github repo: /xamarin/monodroid-samples/tree/master/AdMob

更​​新SDK管理器来下载的谷歌发挥服务群众演员

Updating the SDK manager to download the google play services extras

随着在这个页面的code样品:的http://www.craftworkgames.com/blog/monogame-$c$c-snippets/using-admob-with-monogame/

Following the code sample at this page: http://www.craftworkgames.com/blog/monogame-code-snippets/using-admob-with-monogame/

除了其它方法发现所有在互联网上。我一直很小心添加Java源代码和JAR文件的项目时,选择正确的编译选项,但我从来没有发现任何AD浏览报班,和谷歌移动广告SDK v6.4.1JAR就在那里不再由谷歌支持的,概述这里: https://developers.google.com/mobile-ads- SDK /

As well as other methods found all over the internet. I have been very careful to select the correct build options when adding JAVA sources and JAR files to the project, but I have never found any AdView class, and the "Google Mobile Ads SDK v6.4.1" JAR that is out there is no longer supported by google, as outlined here: https://developers.google.com/mobile-ads-sdk/

如果任何人有任何新时达最新集成AdMob的广告成为MonoGame Android项目的方法,我想答案需要刷新(我会很感激)=)

If anyone has any new and up-to-date methods for integrating AdMob ads into a MonoGame Android project, I think the answers need a refresh (and I will be very grateful) =)

推荐答案

在很长的时间寻找答案和测试多个建议,我终于找到了解决办法。

After a long time looking for answers and testing multiple suggestions, I have finally found the solution.

Xamarin具有可以从组件商店下载一个谷歌播放服务组件。我原本想这一点,但遇到了问题,在VS2012我的解决方案文件。所以这是我做过什么为添加组件手动

Xamarin has a Google Play Services component that can be downloaded from the component store. I had originally tried this, but was running into problems with my solution file in VS2012. So this is what I did to add the component manually:

登录并从 https://components.xamarin.com/view/下载组件googleplayservices /

创建一个文件夹在你的Andr​​oid解决方案,称为lib目录,并从中提取压缩组件文件夹中的dll文件到它

Create a folder in your Android solution called "lib" and extract the dll files from the zipped component folder into it

添加的DLL文件的引用您的项目。您现在应该已经这四个引用补充:

Add the dll files as references to your project. You should now have these four references added:

GooglePlayServicesLib Xamarin.Android.Support.v4 Xamarin.Android.Support.v7.AppCompat Xamarin.Android.Support.v7.MediaRouter

导航到您的项目属性,单击应用程序选项卡(第一个),然后在Java的最大堆大小,在1G(否则你会得到一个Java堆内存不足的错误,而编译)类型。

Navigate into your project properties, click on the Application tab (first one) and under "Java Max Heap Size", type in 1G (otherwise you get a Java Heap out of memory error while compiling)

请确保您的应用程序设置为使用API​​ 14或更高版本(Android 4.0的)。这是可以做到的项目属性页,以及

Make sure your App is set to use API 14 or higher (Android 4.0). This can be done is the project properties page as well

在你的Andr​​oidManifest.xml文件,确保您有以下内容:

In your AndroidManifest.xml file, make sure you have the following:

<activity 
    android:name="com.google.android.gms.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

让您的AdMob单位ID

Get your AdMob Unit ID

更​​改Activity.cs文件来是这样的:

Change your Activity.cs file to something like this:

using Android.Gms.Ads; // Add this include

// Easy constants
private const string AD_UNIT_ID = "YOUR_AD_ID";
private const string TEST_DEVICE_ID = "YOUR_DEVICE_ID";
private AdView adView;

// Change OnCreate and make sure you're not trying to set SetContentView()
// more than once
protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
    Puzzle.ARunningMan.Activity = this;
    var g = new Puzzle.ARunningMan();

    createAds(g.Window);

    g.Run();
}

// Wrapped everything in a function for less confusion.
// Thanks to Dylan Wilson at Craftwork Games for the
// simple layout
private void createAds(AndroidGameWindow window)
{
    var frameLayout = new FrameLayout(this);
    var linearLayout = new LinearLayout(this);

    linearLayout.Orientation = Orientation.Horizontal;
    linearLayout.SetGravity(Android.Views.GravityFlags.Right | Android.Views.GravityFlags.Bottom);

    frameLayout.AddView(window);

    adView = new AdView(this);
    adView.AdUnitId = AD_UNIT_ID;
    adView.AdSize = AdSize.Banner;

    linearLayout.AddView(adView);
    frameLayout.AddView(linearLayout);
    SetContentView(frameLayout);

    try
    {
        // Initiate a generic request.
        var adRequest = new AdRequest.Builder()
            .AddTestDevice(AdRequest.DeviceIdEmulator)
            .AddTestDevice(TEST_DEVICE_ID)
            .Build();

        // Load the adView with the ad request.
        adView.LoadAd(adRequest);
    }
    catch (Exception ex)
    {
        // your error logging goes here
    }
}

编译(将需要一段时间,在第一次),运行它,看在LogCat中窗口标记为广告,其中包含您的设备ID的消息。更多资讯:的http://webtutsdepot.com/2011/12/02/android-sdk-tutorial-get-admob-test-device-id/

设置设备ID字符串,重新编译,运行它

Set the device ID string, recompile, run it

最后,如果你等待大约30-60秒,你会看到一个测试插件显示的一面旗帜。祝你好运所有的,我希望这会有所帮助,因为它是现在的当前信息

And finally, if you wait about 30-60 seconds, you will see a test add show up as a banner. Good luck to all, I hope this helps, as it is now current information