如何在Unity3d中使用Admob InterstitialAd?

时间:2014-08-23 15:50:39

标签: android admob interstitial

Prime31插件不是免费的,我太穷了,无法购买。

https://github.com/guillermocalvo/admob-unity-plugin插件适用于admob横幅,但不支持InterstitialAd。

https://github.com/googleads/googleads-mobile-plugins是谷歌的官方插件,但在Android上崩溃了:

void initAd()
    {
        // Initialize an InterstitialAd.
        interstitial = new InterstitialAd("ca-app-pub-0243484158988577/4626472594");
        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        // Load the interstitial with the request.
        interstitial.LoadAd(request);
    }


? 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2187) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.ActivityThread.access$800(ActivityThread.java:138) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.os.Handler.dispatchMessage(Handler.java:102) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.os.Looper.loop(Looper.java:136) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.ActivityThread.main(ActivityThread.java:5034) 08-23 17:22:52.264: E/AndroidRuntime(17984): at java.lang.reflect.Method.invokeNative(Native Method) 08-23 17:22:52.264: E/AndroidRuntime(17984): at java.lang.reflect.Method.invoke(Method.java:515) 08-23 17:22:52.264: E/AndroidRuntime(17984): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:805) 08-23 17:22:52.264: E/AndroidRuntime(17984): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621) 08-23 17:22:52.264: E/AndroidRuntime(17984): at dalvik.system.NativeStart.main(Native Method) 08-23 17:22:52.264: E/AndroidRuntime(17984): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.admobtest/com.unity3d.player.UnityPlayerNativeActivity}; have you declared this activity in your AndroidManifest.xml? 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.Activity.startActivityForResult(Activity.java:3435) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.Activity.startActivityForResult(Activity.java:3396) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.Activity.startActivity(Activity.java:3638) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.Activity.startActivity(Activity.java:3606) 08-23 17:22:52.264: E/AndroidRuntime(17984): at com.unity3d.player.UnityPlayerProxyActivity.onCreate(Unknown Source) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.Activity.performCreate(Activity.java:5242) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 08-23 17:22:52.264: E/AndroidRuntime(17984): at com.lbe.security.service.core.client.b.x.callActivityOnCreate(Unknown Source) 08-23 17:22:52.264: E/AndroidRuntime(17984): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151) 08-23 17:22:52.264: E/AndroidRuntime(17984): ... 11 more

如何在Unity3d中使用Admob InterstitialAd?

2 个答案:

答案 0 :(得分:0)

android.content.ActivityNotFoundException:无法找到显式活动类{com.example.admobtest / com.unity3d.player.UnityPlayerNativeActivity};你有没有在AndroidManifest.xml中声明这个活动?

这是关键。您的Android清单必须包含以下活动:com.google.android.gms.ads.AdActivity

请检查:https://developers.google.com/mobile-ads-sdk/docs/

答案 1 :(得分:0)

你试过https://github.com/unity-plugins/Unity-Admob吗?我在这方面取得了成功。 代码显示InterstitialAd

void Start () {
        Admob.Instance().interstitialEventHandler += onInterstitialEvent;
    }

   Admob ad = Admob.Instance();
    ad.initAdmob("ca-app-pub-27960454450664210/xxxxxxxxx", "ca-app-pub-279343530664210/xxxxxxxxxxx");

void onInterstitialEvent(string eventName, string msg)
    {
        Debug.Log("handler onAdmobEvent---" + eventName + "   " + msg);
        if (eventName == AdmobEvent.onAdLoaded)
        {
            Admob.Instance().showInterstitial();
        }
    }