我在this教程之后制作了一款安卓游戏,我想在将其上传到Google Play商店之前添加admob广告。我尝试使用this指南,但我很困惑,因为我的应用程序不使用layout.xml,只有一个活动。是否可以在不切换活动的情况下在我的应用的某些部分中投放广告?如果没有,将我的应用程序转换为使用多个活动的应用程序有多难?如有必要,我可以提供任何其他信息。如何通过一项活动将admob广告添加到我的游戏中?
这里是我的活动(我有几个变化的子类):
package com.kilobolt.framework.implementation;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.Window;
import android.view.WindowManager;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.kilobolt.framework.Audio;
import com.kilobolt.framework.FileIO;
import com.kilobolt.framework.Game;
import com.kilobolt.framework.Graphics;
import com.kilobolt.framework.Input;
import com.kilobolt.framework.Screen;
public abstract class AndroidGame extends Activity implements Game {
AndroidFastRenderView renderView;
Graphics graphics;
Audio audio;
Input input;
FileIO fileIO;
Screen screen;
WakeLock wakeLock;
private AdView mAdView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
int frameBufferWidth = isPortrait ? 480: 800;
int frameBufferHeight = isPortrait ? 800: 480;
Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
frameBufferHeight, Config.RGB_565);
float scaleX = (float) frameBufferWidth
/getWindowManager().getDefaultDisplay().getWidth();
float scaleY = (float) frameBufferHeight
/getWindowManager().getDefaultDisplay().getHeight();
renderView = new AndroidFastRenderView(this, frameBuffer);
graphics = new AndroidGraphics(getAssets(), frameBuffer);
fileIO = new AndroidFileIO(this);
audio = new AndroidAudio(this);
input = new AndroidInput(this, renderView, scaleX, scaleY);
screen = getInitScreen();
setContentView(renderView);
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MyGame");
}
@Override
public void onResume() {
super.onResume();
wakeLock.acquire();
screen.resume();
renderView.resume();
}
@Override
public void onPause() {
super.onPause();
wakeLock.release();
renderView.pause();
screen.pause();
if (isFinishing())
screen.dispose();
}
@Override
public Input getInput() {
return input;
}
@Override
public FileIO getFileIO() {
return fileIO;
}
@Override
public Graphics getGraphics() {
return graphics;
}
@Override
public Audio getAudio() {
return audio;
}
@Override
public void setScreen(Screen screen) {
if (screen == null)
throw new IllegalArgumentException("Screen must not be null");
this.screen.pause();
this.screen.dispose();
screen.resume();
screen.update(0);
this.screen = screen;
}
public Screen getCurrentScreen() {
\t return screen;
}
}
好吧,首先,先生,你有两个选择间质和AD浏览,所以这是你指的是?并请发布您希望放置广告的很大一部分活动,所以人人网可以帮助您 – Elltz
谢谢,我将我的活动添加到了我的文章中! –
sir,勾选[post](https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial)..如果您喜欢使用布局,那么您将使用'AdView',下面的答案详细说明了这一点,但你不想使用布局,那么你可以使用'interstitial'请检查** post **它阐述了** Interstitial Add **以及如何将它放入你的应用程序。尝试一下,如果该职位解决您的要求,请删除该问题,基于stackoverflow标准它是一个贫穷的问题,因为缺乏研究.. – Elltz