Andengine Banner Admob黑屏

时间:2017-01-06 20:07:10

标签: android admob andengine google-admob

我正在尝试将广告添加到简单的应用中,但是当应用运行时,手机的屏幕是黑色的。我已经尝试了几乎所有我在Google上做过的解决方案,但事实并非如此。有没有人可以帮助我。感谢

代码

    import android.widget.LinearLayout;
    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdSize;
    import com.google.android.gms.ads.AdView;

    public class comSpriteOlusturmaActivity extends BaseGameActivity {

    private static final int CAMERA_WIDTH = 800;
    private static final int CAMERA_HEIGHT = 480;
    private Camera camera;
    Texture textureResim1, textureResim2;
    TextureRegion textRegResim1, textRegResim2`enter code here`;
    Sprite spriteResim1, spriteResim2;


    public Engine onLoadEngine() 
    {
        camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
        engineOptions.getTouchOptions().setRunOnUpdateThread(true);
        Engine engine = new Engine(engineOptions);

        return engine;
    }


    public void onLoadResources() 
    {
        textureResim1=new Texture(128,128,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        textureResim2=new Texture(128,128,TextureOptions.BILINEAR_PREMULTIPLYALPHA);

        textRegResim1 = TextureRegionFactory.createFromAsset(textureResim1, this, "gfx/blueSmileIcon.png", 0, 0);
        textRegResim2 = TextureRegionFactory.createFromAsset(textureResim2, this, "gfx/yellowSmileIcon.png", 0, 0);

        mEngine.getTextureManager().loadTextures(textureResim1, textureResim2);
    }

    Scene scene;
    public Scene onLoadScene() 
    {
        this.mEngine.registerUpdateHandler(new FPSLogger());    
        this.scene = new Scene();

        spriteResim1 = new Sprite(100, 100, textRegResim1);
        spriteResim2 = new Sprite(400, 100, textRegResim2);

        this.scene.attachChild(spriteResim1);
        this.scene.attachChild(spriteResim2);

        return this.scene;
    }


    public void onLoadComplete() {

    }


    @Override
    protected void onSetContentView() {
        // TODO Auto-generated method stub
        super.onSetContentView();

        setContentView(R.layout.main);
        LinearLayout layout=(LinearLayout)findViewById(R.id.adView);
        AdView adView = new AdView(this);
        adView.setAdUnitId("ca-app-pub-8564721389464451/xxxxxxxx");
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.refreshDrawableState();
        adView.setBackgroundColor(android.graphics.Color.TRANSPARENT);
        adView.setVisibility(AdView.VISIBLE);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice("6C9CA739379F3C6E44B497FAF0876D4D")
                .build();
        adView.loadAd(adRequest);


    }
}

layout:main.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/adView"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:gravity="center_vertical"
       android:orientation="vertical" >
</LinearLayout>

的Manifest.xml:

   <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="serefakuz.com"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    .  <application
        android:allowBackup="true"
        android:label="@string/app_name"
         >
        <activity android:name="www.serefakyuz.com.comSpriteOlusturmaActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

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

    </application>
</manifest>

Android版本4.2.2和java版本1.7 in logcat info:

    01-06 23:01:37.005: I/PersonaManager(22804): getPersonaService() name persona_policy
01-06 23:01:37.276: W/dalvikvm(22804): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
01-06 23:01:37.276: W/dalvikvm(22804): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
01-06 23:01:37.276: W/dalvikvm(22804): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
01-06 23:01:37.276: W/dalvikvm(22804): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
01-06 23:01:37.276: W/dalvikvm(22804): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
01-06 23:01:37.276: W/dalvikvm(22804): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
01-06 23:01:37.276: W/dalvikvm(22804): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
01-06 23:01:37.276: E/dalvikvm(22804): Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
01-06 23:01:37.276: W/dalvikvm(22804): VFY: unable to resolve instanceof 174 (Landroid/support/v4/app/FragmentActivity;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
01-06 23:01:37.276: D/dalvikvm(22804): VFY: replacing opcode 0x20 at 0x0008
01-06 23:01:37.276: E/dalvikvm(22804): Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
01-06 23:01:37.286: W/dalvikvm(22804): VFY: unable to resolve check-cast 174 (Landroid/support/v4/app/FragmentActivity;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
01-06 23:01:37.286: D/dalvikvm(22804): VFY: replacing opcode 0x1f at 0x000c
01-06 23:01:37.316: I/dalvikvm(22804): Could not find method android.security.NetworkSecurityPolicy.getInstance, referenced from method com.google.android.gms.ads.internal.state.h.a
01-06 23:01:37.316: W/dalvikvm(22804): VFY: unable to resolve static method 2946: Landroid/security/NetworkSecurityPolicy;.getInstance ()Landroid/security/NetworkSecurityPolicy;
01-06 23:01:37.316: D/dalvikvm(22804): VFY: replacing opcode 0x71 at 0x0080
01-06 23:01:37.336: I/dalvikvm(22804): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method hyx.a
01-06 23:01:37.336: W/dalvikvm(22804): VFY: unable to resolve virtual method 2339: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
01-06 23:01:37.336: D/dalvikvm(22804): VFY: replacing opcode 0x6e at 0x001c
01-06 23:01:37.426: D/dalvikvm(22804): DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_64_BIT_ABIS
01-06 23:01:37.426: W/dalvikvm(22804): VFY: unable to resolve static field 784 (SUPPORTED_64_BIT_ABIS) in Landroid/os/Build;
01-06 23:01:37.426: D/dalvikvm(22804): VFY: replacing opcode 0x62 at 0x0008
01-06 23:01:37.426: D/dalvikvm(22804): DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_ABIS
01-06 23:01:37.426: W/dalvikvm(22804): VFY: unable to resolve static field 785 (SUPPORTED_ABIS) in Landroid/os/Build;
01-06 23:01:37.426: D/dalvikvm(22804): VFY: replacing opcode 0x62 at 0x0008
01-06 23:01:37.426: D/dalvikvm(22804): DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_64_BIT_ABIS
01-06 23:01:37.426: W/dalvikvm(22804): VFY: unable to resolve static field 784 (SUPPORTED_64_BIT_ABIS) in Landroid/os/Build;
01-06 23:01:37.426: D/dalvikvm(22804): VFY: replacing opcode 0x62 at 0x0012
01-06 23:01:37.426: D/dalvikvm(22804): DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_32_BIT_ABIS
01-06 23:01:37.426: W/dalvikvm(22804): VFY: unable to resolve static field 783 (SUPPORTED_32_BIT_ABIS) in Landroid/os/Build;
01-06 23:01:37.426: D/dalvikvm(22804): VFY: replacing opcode 0x62 at 0x0021
01-06 23:01:37.426: D/dalvikvm(22804): DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_64_BIT_ABIS
01-06 23:01:37.426: I/dalvikvm(22804): DexOpt: unable to optimize static field ref 0x0310 at 0x0d in Lcom/google/android/chimera/container/internal/NativeLibUtils;.a
01-06 23:01:37.426: D/dalvikvm(22804): DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_64_BIT_ABIS
01-06 23:01:37.426: I/dalvikvm(22804): DexOpt: unable to optimize static field ref 0x0310 at 0x17 in Lcom/google/android/chimera/container/internal/NativeLibUtils;.getSupportedAbisForCurrentRuntime
01-06 23:01:37.426: D/dalvikvm(22804): DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_32_BIT_ABIS
01-06 23:01:37.426: I/dalvikvm(22804): DexOpt: unable to optimize static field ref 0x030f at 0x26 in Lcom/google/android/chimera/container/internal/NativeLibUtils;.getSupportedAbisForCurrentRuntime
01-06 23:01:37.436: I/PersonaManager(22804): getPersonaService() name persona_policy
01-06 23:01:37.436: I/dalvikvm(22804): Could not find method android.content.ContextWrapper.createCredentialProtectedStorageContext, referenced from method com.google.android.chimera.ModuleContext.createCredentialProtectedStorageContext
01-06 23:01:37.436: W/dalvikvm(22804): VFY: unable to resolve virtual method 2232: Landroid/content/ContextWrapper;.createCredentialProtectedStorageContext ()Landroid/content/Context;
01-06 23:01:37.436: D/dalvikvm(22804): VFY: replacing opcode 0x6f at 0x0002
01-06 23:01:37.436: I/dalvikvm(22804): Could not find method android.content.ContextWrapper.createDeviceProtectedStorageContext, referenced from method com.google.android.chimera.ModuleContext.createDeviceProtectedStorageContext
01-06 23:01:37.436: W/dalvikvm(22804): VFY: unable to resolve virtual method 2233: Landroid/content/ContextWrapper;.createDeviceProtectedStorageContext ()Landroid/content/Context;
01-06 23:01:37.436: D/dalvikvm(22804): VFY: replacing opcode 0x6f at 0x0002
01-06 23:01:37.436: D/DynamitePackage(22804): Instantiated singleton DynamitePackage.
01-06 23:01:37.436: D/DynamitePackage(22804): Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
01-06 23:01:37.446: I/dalvikvm(22804): Could not find method android.security.NetworkSecurityPolicy.getInstance, referenced from method com.google.android.gms.ads.internal.state.h.a
01-06 23:01:37.446: W/dalvikvm(22804): VFY: unable to resolve static method 2563: Landroid/security/NetworkSecurityPolicy;.getInstance ()Landroid/security/NetworkSecurityPolicy;
01-06 23:01:37.446: D/dalvikvm(22804): VFY: replacing opcode 0x71 at 0x0080
01-06 23:01:37.456: I/dalvikvm(22804): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method zz.a
01-06 23:01:37.456: W/dalvikvm(22804): VFY: unable to resolve virtual method 2120: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
01-06 23:01:37.456: D/dalvikvm(22804): VFY: replacing opcode 0x6e at 0x001c
01-06 23:01:37.486: V/WebViewChromium(22804): Binding Chromium to the main looper Looper (main, tid 1) {4201cdd0}
01-06 23:01:37.486: I/chromium(22804): [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
01-06 23:01:37.486: I/BrowserProcessMain(22804): Initializing chromium process, renderers=0
01-06 23:01:37.516: W/chromium(22804): [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation
01-06 23:01:37.516: E/dalvikvm(22804): Could not find class 'com.google.android.chimera.Activity', referenced from method aat.b
01-06 23:01:37.516: W/dalvikvm(22804): VFY: unable to resolve instanceof 777 (Lcom/google/android/chimera/Activity;) in Laat;
01-06 23:01:37.516: D/dalvikvm(22804): VFY: replacing opcode 0x20 at 0x016f
01-06 23:01:37.516: I/Adreno-EGL(22804): <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8960_KK_2.7_RB1__release_AU ()
01-06 23:01:37.516: I/Adreno-EGL(22804): OpenGL ES Shader Compiler Version: 17.01.12.SPL
01-06 23:01:37.516: I/Adreno-EGL(22804): Build Date: 03/25/14 Tue
01-06 23:01:37.516: I/Adreno-EGL(22804): Local Branch: 
01-06 23:01:37.516: I/Adreno-EGL(22804): Remote Branch: quic/kk_2.7_rb1.32
01-06 23:01:37.516: I/Adreno-EGL(22804): Local Patches: NONE
01-06 23:01:37.516: I/Adreno-EGL(22804): Reconstruct Branch: NOTHING
01-06 23:01:37.546: W/dalvikvm(22804): VFY: unable to resolve static field 1333 (common_full_open_on_phone) in Lcom/google/android/gms/R$drawable;
01-06 23:01:37.546: W/DynamiteModule(22804): Local module descriptor class for com.google.android.gms.piccard.dynamite not found.
01-06 23:01:37.546: I/DynamiteModule(22804): Considering local module com.google.android.gms.piccard.dynamite:0 and remote module com.google.android.gms.piccard.dynamite:0
01-06 23:01:37.546: W/DynamiteModule(22804): Failed to load module via fast routeaje: No acceptable module found. Local version is 0 and remote version is 0.
01-06 23:01:37.556: D/dalvikvm(22804): VFY: replacing opcode 0x60 at 0x0060
01-06 23:01:37.556: D/dalvikvm(22804): DexOpt: couldn't find static field Lig;.common_google_play_services_notification_ticker
01-06 23:01:37.556: W/DynamiteLoaderImpl(22804): Failed to load module version: module com.google.android.gms.piccard.dynamite not found
01-06 23:01:37.556: W/dalvikvm(22804): VFY: unable to resolve static field 6317 (common_google_play_services_notification_ticker) in Lig;
01-06 23:01:37.556: D/dalvikvm(22804): VFY: replacing opcode 0x60 at 0x0092
01-06 23:01:37.566: D/dalvikvm(22804): DexOpt: couldn't find static field Lig;.common_open_on_phone
01-06 23:01:37.566: I/dalvikvm(22804): DexOpt: unable to optimize static field ref 0x18b5 at 0x62 in Llf;.a
01-06 23:01:37.646: I/Ads(22804): Starting ad request.
01-06 23:01:37.656: I/Ads(22804): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
01-06 23:01:37.686: D/AndEngine(22804): UpdateThread interrupted. Don't worry - this Exception is most likely expected!
01-06 23:01:37.686: D/AndEngine(22804): java.lang.InterruptedException
01-06 23:01:37.686: D/AndEngine(22804):     at java.lang.Object.wait(Native Method)
01-06 23:01:37.686: D/AndEngine(22804):     at java.lang.Object.wait(Object.java:364)
01-06 23:01:37.686: D/AndEngine(22804):     at org.anddev.andengine.engine.Engine$State.waitUntilCanUpdate(Engine.java:712)
01-06 23:01:37.686: D/AndEngine(22804):     at org.anddev.andengine.engine.Engine.yieldDraw(Engine.java:462)
01-06 23:01:37.686: D/AndEngine(22804):     at org.anddev.andengine.engine.Engine.onTickUpdate(Engine.java:453)
01-06 23:01:37.686: D/AndEngine(22804):     at org.anddev.andengine.engine.Engine$UpdateThread.run(Engine.java:675)
01-06 23:01:37.696: I/PersonaManager(22804): getPersonaService() name persona_policy
01-06 23:01:37.716: W/DynamiteLoaderImpl(22804): Failed to load module version after staging: module com.google.android.gms.piccard.dynamite not found
01-06 23:01:37.716: W/DynamiteModule(22804): Local module descriptor class for com.google.android.gms.piccard.dynamite not found.
01-06 23:01:37.716: I/DynamiteModule(22804): Considering local module com.google.android.gms.piccard.dynamite:0 and remote module com.google.android.gms.piccard.dynamite:0
01-06 23:01:37.716: E/AppStreamingFragment(22804): No acceptable module found. Local version is 0 and remote version is 0.
01-06 23:01:37.726: D/DynamitePackage(22804): Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
01-06 23:01:37.726: I/Ads(22804): Starting ad request.
01-06 23:01:37.736: I/Ads(22804): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
01-06 23:01:37.786: D/OpenGLRenderer(22804): Enabling debug mode 0
01-06 23:01:37.906: I/dalvikvm(22804): Total arena pages for JIT: 11
01-06 23:01:37.906: I/dalvikvm(22804): Total arena pages for JIT: 12
01-06 23:01:37.906: I/dalvikvm(22804): Total arena pages for JIT: 13
01-06 23:01:37.906: I/dalvikvm(22804): Total arena pages for JIT: 14
01-06 23:01:41.981: I/dalvikvm(22804): Could not find method android.webkit.WebSettings.setMixedContentMode, referenced from method com.google.android.gms.ads.internal.webview.m.<init>
01-06 23:01:41.981: W/dalvikvm(22804): VFY: unable to resolve virtual method 2837: Landroid/webkit/WebSettings;.setMixedContentMode (I)V
01-06 23:01:41.981: D/dalvikvm(22804): VFY: replacing opcode 0x6e at 0x0058
01-06 23:01:42.051: I/dalvikvm(22804): Total arena pages for JIT: 15
01-06 23:01:42.872: I/Ads(22804): Scheduling ad refresh 60000 milliseconds from now.
01-06 23:01:42.882: W/ActivityThread(22804): ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());
01-06 23:01:42.912: I/Ads(22804): Ad finished loading.
01-06 23:01:42.932: I/Ads(22804): Scheduling ad refresh 60000 milliseconds from now.
01-06 23:01:42.932: I/Ads(22804): Ad finished loading.
01-06 23:01:43.052: I/chromium(22804): [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
01-06 23:01:43.052: I/chromium(22804): [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
01-06 23:01:43.693: I/chromium(22804): [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
01-06 23:02:42.876: I/Ads(22804): Ad is not visible. Not refreshing ad.
01-06 23:02:42.876: I/Ads(22804): Scheduling ad refresh 60000 milliseconds from now.
01-06 23:02:42.936: I/Ads(22804): Ad is not visible. Not refreshing ad.
01-06 23:02:42.936: I/Ads(22804): Scheduling ad refresh 60000 milliseconds from now.

1 个答案:

答案 0 :(得分:0)

您需要在main.xml中使用AdView 像这样:

<script>
$("#dropdownlist").kendoDropDownList({
  dataSource: [ "/Apples", "/Oranges" ],

  // None of these templates appear to fix the search text.  
  // Kendo is using the dataSource item to search instead of the template output.
  // I want to be able to search using 'a' (for Apples) or 'o' (for Oranges).  
  // If I use '/' then it cycles through the items which proves to me that the search is not using templated text.

  template: function(t) { return t.name.slice(1); },
  valueTemplate: function(t) { return t.name.slice(1); },
  optionLabelTemplate : function (t) { return t.name.slice(1); },

});
</script>

https://firebase.google.com/docs/admob/android/quick-start