首页 > Web开发 > 详细

cocos2d-js添加百度MSSP插屏(通过jsb反射机制)

时间:2015-12-18 21:09:37      阅读:434      评论:0      收藏:0      [点我收藏+]

1、导入jar包。。。。

2、修改AndroidManifest.xml文件

添加:

<meta-data android:name="BaiduMobAd_APP_ID" android:value="替换为appid"/>
<activity android:configChanges="keyboard|keyboardHidden|orientation" android:name="com.baidu.mobads.AppActivity"/>

添加权限:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>  

3、修改AppActivity.java文件

//百度
import com.baidu.mobads.InterstitialAd;
import com.baidu.mobads.InterstitialAdListener;


// The name of .so is specified in AndroidMenifest.xml. NativityActivity will load it automatically for you.
// You can use "System.loadLibrary()" to load other .so files.

public class AppActivity extends Cocos2dxActivity{
    private static AppActivity app = null;//百度
    public static InterstitialAd interAd;//百度
    static String hostIPAdress="0.0.0.0";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        //百度
        app = this;
        String adPlaceId = "代码位id"; // 重要:不填写代码位id不能出广告
        interAd=new InterstitialAd(this, adPlaceId);
        interAd.setListener(new InterstitialAdListener(){
            @Override
            public void onAdClick(InterstitialAd arg0) {
            }
            @Override
            public void onAdDismissed() {
                interAd.loadAd();
            }
            @Override
            public void onAdFailed(String arg0) {
            }
            @Override
            public void onAdPresent() {
            }
            @Override
            public void onAdReady() {
            }
        });
        interAd.loadAd();
        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 sdksMSSP(final String title,final String message) {
        //这里一定要使用runOnUiThread
        app.runOnUiThread(new Runnable() {
            @Override
            public void run() {
              if(interAd.isAdReady()){
                    interAd.showAd(app);
                }else{
                    interAd.loadAd();
                }
            }
        });

    }

4、js文件直接调用:

jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "sdksMSSP", "(Ljava/lang/String;Ljava/lang/String;)V", "title", "hahahahha");

 

cocos2d-js添加百度MSSP插屏(通过jsb反射机制)

原文:http://www.cnblogs.com/recock/p/5058119.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!