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");
时间: 2024-10-12 23:06:18