1、把广点通的jar包加入libs文件夹
2、修改AndroidManifest.xml文件
添加权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES"/>
添加:
<service android:exported="false" android:name="com.qq.e.comm.DownloadService"/> <activity android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:name="com.qq.e.ads.ADActivity"/>
3、修改AppActivity.java文件
//广点通 import com.qq.e.ads.interstitial.AbstractInterstitialADListener; import com.qq.e.ads.interstitial.InterstitialAD; import android.util.Log; public class AppActivity extends Cocos2dxActivity{ public static InterstitialAD iad;//广点通 private static AppActivity app = null;//广点通 static String hostIPAdress="0.0.0.0"; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); //广点通 app = this; iad = new InterstitialAD(this, "1104920573", "1030403721986967"); iad.setADListener(new AbstractInterstitialADListener() { @Override public void onNoAD(int arg0) { Log.i("AD_DEMO", "LoadInterstitialAd Fail:" + arg0); } @Override public void onADReceive() { iad.show(); } }); if(nativeIsLandScape()) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } if(nativeIsDebug()){ getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } hostIPAdress = getHostIpAddress(); } public static void sdksGDT(final String title,final String message) { //这里一定要使用runOnUiThread app.runOnUiThread(new Runnable() { @Override public void run() { iad.loadAD(); } }); }
注:发布时请将"ba33fa857c2bb430ebab705ce4e326d9"测试key替换为平台申请key
最后通过js调用即可:
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "sdksGDT", "(Ljava/lang/String;Ljava/lang/String;)V", "title", "hahahahha");
时间: 2024-10-11 21:14:06