我尝试在游戏中广告。我用了一个发动机。它打开了4.4.2模拟器和我的索尼Xperia Z2。但是,当我尝试使用4.1.2模拟器打开时,它会停止工作。我试着和朋友打电话4.1。相同的结果
@Override
protected void onSetContentView() {
final FrameLayout frameLayout = new FrameLayout(this);
final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT);
AdView adView = new AdView(this);
adView.setAdUnitId("ca-app-pub-9924350594770048/3316988217");
adView.setAdSize(AdSize.BANNER);
adView.refreshDrawableState();
adView.setVisibility(AdView.VISIBLE);
final FrameLayout.LayoutParams adViewLayoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
AdRequest adreq = new AdRequest.Builder().build();
adView.loadAd(adreq);
this.mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setRenderer(mEngine);
final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(
super.createSurfaceViewLayoutParams());
frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
frameLayout.addView(adView, adViewLayoutParams);
this.setContentView(frameLayout, frameLayoutLayoutParams);
}
有我的代码。
和logcat
03-17 22:45:17.668: W/dalvikvm(658): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
03-17 22:45:17.687: E/AndroidRuntime(658): FATAL EXCEPTION: main
03-17 22:45:17.687: E/AndroidRuntime(658): java.lang.NoSuchMethodError: android.widget.FrameLayout$LayoutParams.<init>
03-17 22:45:17.687: E/AndroidRuntime(658): at com.oxygenuygulamalari.maymuntesti.MainActivity.onSetContentView(MainActivity.java:89)
03-17 22:45:17.687: E/AndroidRuntime(658): at org.anddev.andengine.ui.activity.BaseGameActivity.onCreate(BaseGameActivity.java:64)
03-17 22:45:17.687: E/AndroidRuntime(658): at android.app.Activity.performCreate(Activity.java:5008)
03-17 22:45:17.687: E/AndroidRuntime(658): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
03-17 22:45:17.687: E/AndroidRuntime(658): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
03-17 22:45:17.687: E/AndroidRuntime(658): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-17 22:45:17.687: E/AndroidRuntime(658): at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-17 22:45:17.687: E/AndroidRuntime(658): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-17 22:45:17.687: E/AndroidRuntime(658): at android.os.Handler.dispatchMessage(Handler.java:99)
03-17 22:45:17.687: E/AndroidRuntime(658): at android.os.Looper.loop(Looper.java:137)
03-17 22:45:17.687: E/AndroidRuntime(658): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-17 22:45:17.687: E/AndroidRuntime(658): at java.lang.reflect.Method.invokeNative(Native Method)
03-17 22:45:17.687: E/AndroidRuntime(658): at java.lang.reflect.Method.invoke(Method.java:511)
03-17 22:45:17.687: E/AndroidRuntime(658): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-17 22:45:17.687: E/AndroidRuntime(658): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-17 22:45:17.687: E/AndroidRuntime(658): at dalvik.system.NativeStart.main(Native Method)
03-17 22:45:20.547: I/dalvikvm(658): Total arena pages for JIT: 11
03-17 22:45:20.547: I/dalvikvm(658): Total arena pages for JIT: 12
03-17 22:45:20.557: I/dalvikvm(658): Total arena pages for JIT: 13
03-17 22:45:20.568: I/dalvikvm(658): Total arena pages for JIT: 14
03-17 22:45:20.568: I/dalvikvm(658): Total arena pages for JIT: 15
03-17 22:45:20.568: I/dalvikvm(658): Total arena pages for JIT: 16
03-17 22:45:20.577: I/dalvikvm(658): Total arena pages for JIT: 17
03-17 22:45:20.677: I/dalvikvm(658): Total arena pages for JIT: 18
03-17 22:45:20.767: D/dalvikvm(658): DexOpt: --- BEGIN 'ads-2102557420.jar' (bootstrap=0) ---
03-17 22:45:21.057: D/dalvikvm(658): DexOpt: --- END 'ads-2102557420.jar' (success) ---
03-17 22:45:21.057: D/dalvikvm(658): DEX prep '/data/data/com.oxygenuygulamalari.maymuntesti/cache/ads-2102557420.jar': unzip in 3ms, rewrite 288ms
03-17 22:45:41.497: W/Ads(658): There was a problem getting an ad response. ErrorCode: 0
答案 0 :(得分:0)
将Admob添加到AndEngine(将广告的位置设置为底部):
@Override
protected void onSetContentView() {
final RelativeLayout relativeLayout = new RelativeLayout(this);
final FrameLayout.LayoutParams relativeLayoutLayoutParams = new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
this.mRenderSurfaceView = new RenderSurfaceView(this);
this.mRenderSurfaceView.setRenderer(this.mEngine, this);
final android.widget.RelativeLayout.LayoutParams surfaceViewLayoutParams = new RelativeLayout.LayoutParams(BaseGameActivity.createSurfaceViewLayoutParams());
surfaceViewLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
relativeLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
FrameLayout frameLayout = new FrameLayout(this);
FrameLayout.LayoutParams fparams=new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
adView = new AdView(this);
final FrameLayout.LayoutParams adViewLayoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
adView.setAdUnitId("xxxxx");
adView.setAdSize(AdSize.SMART_BANNER);
adView.refreshDrawableState();
frameLayout.addView(adView,adViewLayoutParams);
relativeLayout.addView(frameLayout,fparams);
this.setContentView(relativeLayout, relativeLayoutLayoutParams);
}