一、简介

主要介绍在Android项目中如何集成 UNAD SDK的H5游戏:

二、集成

1、在自己的Application 中初始化SDK

TEST_APPID为测试appid,上线请替换正式的APPID

UNAD.initialize(new UNADConfig.Builder()
                            // true-屏蔽个性化推荐广告(关闭)
                            //false-不屏蔽个性化推荐广告(打开)
                            //默认false
                            .setPersonalRecommend(false)
                            .setDebug(true).build(),
                    "TEST_APPID", this, new UNAD.InitCallback() {
                        @Override
                        public void onSuccess() {

                            Log.e("unadsdk", "UI:onSuccess");
                        }

                        @Override
                        public void onError(UnadError error) {
                            Log.e("unadsdk", "UI:onError");
                        }
                    });xxxxxxxxxx UNAD.initialize(new UNADConfig.Builder()                            // true-屏蔽个性化推荐广告(关闭)                            //false-不屏蔽个性化推荐广告(打开)                            //默认false                            .setPersonalRecommend(false)                            .setDebug(true).build(),                    "TEST_APPID", this, new UNAD.InitCallback() {                        @Override                        public void onSuccess() {                            Log.e("unadsdk", "UI:onSuccess");                        }                        @Override                        public void onError(UnadError error) {                            Log.e("unadsdk", "UI:onError");                        }                    });UNAD.initialize("TEST_APPID",this,new UNAD.InitCallback(){      @Override      public void onSuccess() {      }      @Override      public void onError(UnadError error) {      }    });java

2、在AndroidManifest配置

   H5入口,H5广告必须
<activity
            android:name="com.unad.sdk.GameAdActivity"
            android:label="@string/app_name"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:windowSoftInputMode="stateHidden|stateAlwaysHidden"
            >
        </activity>
       微信登录回调
        <activity
            android:name="您的包名.wxapi.WXEntryActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:launchMode="singleTop"/>

3、初始化广告

       UNAD广告位id
       String adid="TEST_UNIT_ID";
        微信APPID
        String wxappid="wx912b53cd64a9c0b8";
        UNADGameAdLoader unadGameAdLoader=new UNADGameAdLoader(this,adid,new UNADGameAdLoader.UNADGameAdListener(){
            @Override
            public void onADError(UnadError var1) {
                Toast.makeText(MainActivity.this,var1.getMessage(),Toast.LENGTH_SHORT).show();
                #H5加载失败
            }
            @Override
            public void wxLogin() {
                微信登录,这里您需要集成微信opensdk,进行微信登录功能
                IWXAPI mWeixinAPI = WXAPIFactory.createWXAPI(MainActivity.this, wxappid, false);
                SendAuth.Req req = new SendAuth.Req();
                req.scope = "snsapi_userinfo";
                req.state = "wechat_sdk_demo_test";
                mWeixinAPI.sendReq(req);
            }
        });
        unadGameAdLoader.load();

4、广播通知H5微信登录

 在您的WXEntryActivity onResp方法中获取到了微信的code,通过广播发送给SDK
 code即微信登录获取到的微信code

    Intent intent = new Intent();
    intent.setAction("com.unad.adbroadcast");
    intent.putExtra("code",code);
    sendBroadcast(intent);

1、测试广告位ID TEST_UNIT_ID 应用上线时请替换为正式的广告位ID

2、详细参考demo

results matching ""

    No results matching ""