zoukankan      html  css  js  c++  java
  • cocos2d-js添加百度MSSP插屏(通过jsb反射机制)

    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");
  • 相关阅读:
    html中frameset的详细使用方法
    日期控件API
    限制input输入类型(多种方法实现)
    springmvc导出excel并弹出下载框
    Spring mvc 验证码的做法
    Spring Boot 集成MyBatis
    Spring Boot 实践折腾记(三):三板斧,Spring Boot下使用Mybatis
    支付系统架构
    javaScript事件(六)事件类型之滚轮事件
    你不是真正的快乐
  • 原文地址:https://www.cnblogs.com/recock/p/5058119.html
Copyright © 2011-2022 走看看