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

cocos2d-js添加百度appx的插屏广告(通过jsb反射机制)

时间:2015-06-12 00:43:09      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:

本来一直用的anysdk接入广告,结果从前几天开始,百度商店的审核总是通不过,结果一问才知道:要上传到百度商店就必须要用百度的appx(真的是各种坑,我们这些个人开发者迟早要被你们大公司玩死),没办法只能用appx了,谁叫百度的量还是挺大的呢

下面是接入过程:

【1】按照百度appx给的AppXSample,先把libs文件夹下的baidu_cuid.jar和baidu_appx_android_2.0.0.jar两个jar包拷贝至项目libs里面。

【2】把AppXSample下的res文件夹下的文件全部拷贝至项目res,注意文件合并

【3】修改AndroidManifest.xml

添加:activity

<!-- 移动云AppX SDK -->
        <activity android:name="com.baidu.appx.ui.BDInnerBrowser" />

        <receiver android:name="com.baidu.appx.app_download.CompleteReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
                <action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED" />

                <data android:scheme="package" />
                <!-- 注意!! 这句必须要加,否则接收不到安装完成广播 -->
            </intent-filter>
        </receiver>

添加两个权限:

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

【4】修改AppActivity.java文件

package org.cocos2dx.javascript;

import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
import android.content.pm.ActivityInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Environment;
import android.view.WindowManager;
//百度appx
import com.baidu.appx.BDInterstitialAd;
import com.baidu.appx.BDInterstitialAd.InterstitialAdListener;
import android.util.Log;



public class AppActivity extends Cocos2dxActivity{
        
    //百度appx
    private static AppActivity app = null;
    private static String TAG = "AppX_Interstitial";
    private static BDInterstitialAd appxInterstitialAdView;
    
    static String hostIPAdress="0.0.0.0";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//百度appx app
= this;//百度appx appxInterstitialAdView = new BDInterstitialAd(this, "h8g8XsOYSXo5uGnGXdAHOAUw", "zqGAV5GBdAPWt0NWuPDylS2E"); appxInterstitialAdView.setAdListener(new InterstitialAdListener() { @Override public void onAdvertisementDataDidLoadFailure() { Log.e(TAG, "load failure"); } @Override public void onAdvertisementDataDidLoadSuccess() { Log.e(TAG, "load success"); } @Override public void onAdvertisementViewDidClick() { Log.e(TAG, "on click"); } @Override public void onAdvertisementViewDidHide() { Log.e(TAG, "on hide"); } @Override public void onAdvertisementViewDidShow() { Log.e(TAG, "on show"); } @Override public void onAdvertisementViewWillStartNewIntent() { Log.e(TAG, "leave"); } }); appxInterstitialAdView.loadAd(); } public static void sdks(final String title,final String message) { //这里一定要使用runOnUiThread app.runOnUiThread(new Runnable() { @Override public void run() { if (appxInterstitialAdView.isLoaded()) { appxInterstitialAdView.showAd(); } else { Log.i(TAG, "AppX Interstitial Ad is not ready"); appxInterstitialAdView.loadAd(); } } }); } }

其中sdks()方法为jsb反射回调方法,目的是显示插屏广告

ps:要把参数换成自己的api_key和推广位ID

【5】最后一步就是在js代码中添加调用sdks()的方法

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

 

cocos2d-js添加百度appx的插屏广告(通过jsb反射机制)

标签:

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

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