0

我制作了一款游戏,并在上面使用了一家广告公司(StartApp)。我想在上面使用插页式广告。我按照他们展示的步骤进行操作,但无法实现。我收到错误。这是LogCat:

http://i.stack.imgur.com/SaIXE.png

这是代码:

游戏活动.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();
}
4

3 回答 3

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();
}

并在清单文件中更新

于 2014-02-06T14:04:24.693 回答
0

检查 Manifest.xml 文件。确保你在那里写了正确的包名。

于 2014-02-06T15:16:28.163 回答
0

你不能使用

startAppAd.showAd();
startAppAd.loadAd();

在 Scene 类 (MenuScene) 中。相反,您可以尝试以下方法。在 GameActivity 类中,您必须具有 KeyEvent 方法。将代码放在那里显示 startApp 广告,如下所示,

@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; 
}

问候, 迪帕克

于 2014-06-02T19:21:13.717 回答