码迷,mamicode.com
首页 > Web开发 > 详细

cocos2d-js添加广点通插屏(通过jsb反射机制)

时间:2015-11-29 21:24:38      阅读:918      评论:0      收藏:0      [点我收藏+]

标签:

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");

 

cocos2d-js添加广点通插屏(通过jsb反射机制)

标签:

原文地址:http://www.cnblogs.com/recock/p/5005322.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!