zoukankan      html  css  js  c++  java
  • cocos2d-js添加百通广告(通过jsb反射机制)

    1、导入jar包,包括so文件

    2、配置AndroidManifest.xml文件,添加:

    <!-- BDAPPUNIONSDK start -->
            <activity android:configChanges="keyboardHidden|orientation|screenSize" android:name="com.baidu.ops.appunion.sdk.activity.AppListActivity"/>
            <activity android:configChanges="keyboardHidden|orientation|screenSize" android:name="com.baidu.ops.appunion.sdk.activity.WebActivity"/>
    
            <service android:exported="false" android:label="AppUnionService" android:name="com.baidu.ops.appunion.sdk.service.AppUnionService"/>
    
            <meta-data android:name="BDAPPUNIONSDK_APIKEY" android:value="替换为自己的appkey"/>
            <!-- BDAPPUNIONSDK end -->

    添加权限:

        <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
        <uses-permission android:name="android.permission.GET_TASKS"/>
        <uses-permission android:name="android.permission.WAKE_LOCK"/>
        <!-- 用于记录uid -->
        <uses-permission android:name="android.permission.WRITE_SETTINGS"/>

    3、修改AppActivity.java文件

    //百通
    import com.baidu.ops.appunion.sdk.AppUnionSDK;
    import com.baidu.ops.appunion.sdk.banner.BaiduBanner;
    import com.baidu.ops.appunion.sdk.banner.BannerType;
    
    public class AppActivity extends Cocos2dxActivity{
        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;////百通
            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 sdksBT(final String title,final String message) {
        //这里一定要使用runOnUiThread
            app.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                           AppUnionSDK appxInterstitialAdView = AppUnionSDK.getInstance(app);
                        appxInterstitialAdView.initSdk();
                        appxInterstitialAdView.showInterstitialAd(app);
                }
            });
        }

    4、最后通过js调用即可:

    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "sdksBT", "(Ljava/lang/String;Ljava/lang/String;)V", "title", "hahahahha");
  • 相关阅读:
    第三课 本代码用于学习vue根组件数据的各种绑定
    第七课 键入事件,点击绑定事件,数据判断及删除事件
    第九课 代码封装localstorage
    第八课 没有封装localstorage
    第五课 vue的事件调用自定义方法
    第六课 点击事件调用自定义方法
    new多个文件编程和split单个文件多个窗口编程
    线性表特点和用法总结
    scanf在输入整型数据和字符型数据时的不同
    tasklet源码注释翻译
  • 原文地址:https://www.cnblogs.com/recock/p/4738905.html
Copyright © 2011-2022 走看看