我做了一个游戏并在其上使用了一个广告公司(StartApp)。我想在其上使用非页内广告。我按照他们展示的步骤但无法实现。我收到了错误。这是LogCat:
http://i.stack.imgur.com/SaIXE.png
以下是代码:
GameActivity.java
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws IOException
{
StartAppAd.init(this, "10254544", "20454573");
}
MenuScene.java
private StartAppAd startAppAd = new StartAppAd(activity);
@Override
public void createScene() {
startAppAd.showAd();
startAppAd.loadAd();
}
答案 0 :(得分:0)
尝试此代码,您也应该更新清单文件
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StartAppSearch.showSearchBox(this);
StartAppAd.init(this, "107181003", "211487617");
StartAppSearch.init(this, "107181003", "211487617");
btnnext.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startAppAd.showAd(); // show the ad
startAppAd.loadAd(); //load next add
Intent intent=new Intent(getApplicationContext(),Second.class);
startActivity(intent);
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
boolean _active = true;
}
return true;
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
startAppAd.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
startAppAd.onResume();
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
private StartAppAd startAppAd = new StartAppAd(this);
@Override
public void onBackPressed() {
startAppAd.onBackPressed();
super.onBackPressed();
}
并在清单文件中更新
答案 1 :(得分:0)
检查Manifest.xml文件。确保你在那里写了正确的包名。
答案 2 :(得分:0)
您无法使用
startAppAd.showAd();
startAppAd.loadAd();
在Scene类(MenuScene)中。相反,你可以尝试以下方法。 在GameActivity类中,您必须拥有KeyEvent方法。将代码显示在那里,如下所示,
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
if(SceneManager.getInstance().getCurrentSceneType().toString() == "SCENE_MENU"){
try{
startAppAd.showAd(); // show the ad
startAppAd.loadAd(); // load the next ad
}catch(Exception e){
}
}
try{
SceneManager.getInstance().getCurrentScene().onBackKeyPressed();
}catch(Exception e){
}
}
return false;
}
此致 迪帕克