我正在用C ++编写跨平台应用程序,现在我想实现admob。我不知道怎么做,现在我试图使用JNI。但是在调用interstitial.isLoaded()时,我的应用程序 崩溃没有错误。任何解决方案将不胜感激
编辑解决方案
在.cpp
下#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t,
"com.example.mygame/mygame",
"loadAdmob",
"()V"))
{
t.env->CallStaticVoidMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
}
#endif
在Cocos2dxActivity下
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
// Create the interstitial.
final String ADMOB_ID = "my-id";
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(ADMOB_ID);
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().addTestDevice("device-id").build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);
appActivity = this;
}
public static void loadAdmob() {
appActivity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
if (interstitial.isLoaded()) {
interstitial.show();
}
}
});
}