package demo;
import android.support.multidex.MultiDexApplication;
import android.util.Log;
//这些包要等小米的广告sdk包引入后再引入
import com.xiaomi.ad.mediation.internal.config.IMediationConfigInitListener;
import com.xiaomi.ad.mediation.mimonew.MIMOAdSdkConfig;
import com.xiaomi.ad.mediation.mimonew.MiMoNewSdk;
import com.cszs.jgdnc.mi.R; //这里包名要改
import com.xiaomi.gamecenter.sdk.MiCommplatform;
import com.xiaomi.gamecenter.sdk.MiErrorCode;
import com.xiaomi.gamecenter.sdk.OnInitProcessListener;
import com.xiaomi.gamecenter.sdk.OnLoginProcessListener;
import com.xiaomi.gamecenter.sdk.entry.MiAccountInfo;
import com.xiaomi.gamecenter.sdk.entry.MiAppInfo;
import java.util.List;
/**
* Copyright (C) 2013, Xiaomi Inc. All rights reserved.
*/
public class MMApplication extends MultiDexApplication {
private static final String TAG = "MMApplication";
private static MainActivity mActivity;
private static final String APPID = "2882303761520039686";
@Override
public void onCreate() {
super.onCreate();
//网游sdk初始化
MiAppInfo appInfo = new MiAppInfo();
//正式环境下的appid
appInfo.setAppId(APPID);
//测试广告包的appid
// appInfo.setAppId("2882303761517973922");
//正式包体的appKey
appInfo.setAppKey("5852003941686");
// appInfo.setAppKey("");
Log.d("initSDK", "initSDK");
MiCommplatform.Init(this, appInfo, new OnInitProcessListener() {
@Override
public void finishInitProcess(List loginMethod, int gameConfig) {
Log.i("Demo","Init success");
}
@Override
public void onMiSplashEnd() {
//小米闪屏⻚结束回调,小米闪屏可配,无闪屏也会返回此回调,游戏的闪屏应当在收到此回调之后
}
});
}
}
public void initSDK(MainActivity _mActivity){
mActivity =_mActivity;
MiCommplatform.getInstance().miLogin(mActivity,
new OnLoginProcessListener()
{
@Override
public void finishLoginProcess(int code , MiAccountInfo arg1)
{
switch( code )
{
case MiErrorCode.MI_XIAOMI_PAYMENT_SUCCESS:// 登陆成功
Log.i(TAG,"小米登录成功");
//获取用户的登陆后的UID(即用户唯一标识)
String uid = arg1.getUid();
//以下为获取session并校验流程,如果是网络游戏必须校验,(12小时过期)
//获取用户的登陆的Session(请参考5.3.3流程校验Session有效性)
String session = arg1.getSessionId();
//请开发者完成将uid和session提交给开发者自己服务器进行session验证
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_LOGIN_FAIL:
Log.i(TAG,"登录失败");
// 登陆失败
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_CANCEL:
Log.i(TAG,"取消登录");
// 取消登录
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_ACTION_EXECUTED:
//登录操作正在进行中
Log.i(TAG,"登录操作正在进行中");
break;
default:
// 登录失败
Log.i(TAG,"登录失败");
break;
}
}
} );
}
public void exitGame(){
MiCommplatform.getInstance().miAppExit( this, new OnExitListner()
{
@Override
public void onExit( int code )
{
Log.i("Demo","小米游戏退出");
if ( code == MiErrorCode.MI_XIAOMI_EXIT )
{
android.os.Process.killProcess( android.os.Process.myPid() );
}
}
} );
}
public void initSDK(MainActivity _mActivity){
mActivity =_mActivity;
//广告sdk初始化
Log.i(TAG,"广告sdk初始化");
MiMoNewSdk.init(this, APPID, getString(R.string.app_name),
new MIMOAdSdkConfig.Builder()
.setDebug(false)
.setStaging(false).build(), new IMediationConfigInitListener() {
@Override
public void onSuccess() {
Log.i(TAG,"广告sdk初始化成功");
}
@Override
public void onFailed(int errorCode) {
Log.i(TAG,"广告sdk初始化失败"+errorCode);
}
});
MiCommplatform.getInstance().miLogin(mActivity,
new OnLoginProcessListener()
{
@Override
public void finishLoginProcess(int code , MiAccountInfo arg1)
{
switch( code )
{
case MiErrorCode.MI_XIAOMI_PAYMENT_SUCCESS:// 登陆成功
Log.i(TAG,"小米登录成功");
//获取用户的登陆后的UID(即用户唯一标识)
String uid = arg1.getUid();
//以下为获取session并校验流程,如果是网络游戏必须校验,(12小时过期)
//获取用户的登陆的Session(请参考5.3.3流程校验Session有效性)
String session = arg1.getSessionId();
//请开发者完成将uid和session提交给开发者自己服务器进行session验证
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_LOGIN_FAIL:
Log.i(TAG,"登录失败");
// 登陆失败
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_CANCEL:
Log.i(TAG,"取消登录");
// 取消登录
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_ACTION_EXECUTED:
//登录操作正在进行中
Log.i(TAG,"登录操作正在进行中");
break;
default:
// 登录失败
Log.i(TAG,"登录失败");
break;
}
}
} );
}
广告类型
|
测试广告位ID
|
横幅
|
28e12557924f47bcde1fb4122527a6bc
|
横版插屏广告
|
dc7cc080d643693f4f835b1a7718283d
|
竖版插屏广告
|
a61183c0f3899bc138a320925df3d862
|
横版全屏插屏广告
|
756c0d2cdb935266522249c90ca04dbe
|
竖版全屏插屏广告
|
b539ee9934e2e869c6aced477a02fa0e
|
横版激励视频广告
|
feff23d4d67802626433de32bd1b327d
|
竖版激励视频广告
|
95297e164e1dfb6c0ce4a2eaf61cc791
|
横版开屏
|
f22820b630d6d453f956cbe31235d11a
|
原生模板 - 上文下图(带标题)
|
bfa05071958648861ef32be94c4ac200
|
原生模板 - 左文右图(带标题)
|
77c1a503091c597f8a03d57010637d7c
|
原生模板 - 左图右文(带标题A版)
|
8db571afaf731ec727d42db9894d688d
|
原生模板 - 左图右文(带标题B版)
|
5d1bab599fc4443c17021ea75dfa729d
|
原生模板 - 上图下文(大图)
|
671f83d6d6c1f2356c1a14de9f7ec9cf
|
原生模板 - 上图下文(组图)
|
b72a783f1f1952c09e429f777cf2426e
|
自渲染 - 信息流大图
|
c09e2a394366b0819fd3ac2bc142ed20
|
自渲染 - 信息流小图
|
11cc7b67acfc800ac6228af78f122acf
|
自渲染 - 信息流组图
|
949f4411ceceb8d14042dffb1112af6b
|
**/
/**
在 res/xml/下添加文件 mimo_file_paths.xml 参考demo
内容:
**/
AndroidMainfest.xml新增provider声明:
//声明变量先:
private ViewGroup gameContainer;
public ViewGroup banner_container;
public void initEngine()
{
mProxy = new RuntimeProxy(this);
mPlugin = new GameEngine(this);
mPlugin.game_plugin_set_runtime_proxy(mProxy);
mPlugin.game_plugin_set_option("localize","false");
mPlugin.game_plugin_set_option("gameUrl", App_Startup_Entry);
mPlugin.game_plugin_init(3);
View gameView = mPlugin.game_plugin_get_view();
this.setContentView(R.layout.activity_main);
this.gameContainer = findViewById(R.id.game_container);
this.banner_container = findViewById(R.id.banner_container);
this.gameContainer.addView(gameView);
mProxy.InitAD();
isLoad=true;
}
public void onUserAgreed(JSONObject jsonObj, final ValueCallback callback){
Log.d("UserAgreed", "Login info = " + jsonObj.toString());
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
/**
* 如果你的targetSDKVersion >= 23,就要主动申请好权限。如果您的App没有适配到Android6.0(即targetSDKVersion < 23),那么只需要在这里直接调用fetchSplashAd方法。
*
*/
checkAndRequestPermissions();
} else {
/**
* 如果是Android6.0以下的机器,默认在安装时获得了所有权限,可以直接调用SDK。
*/
}
MiCommplatform.getInstance().onUserAgreed(this);
MiCommplatform.getInstance().miLogin(this,
new OnLoginProcessListener()
{
@Override
public void finishLoginProcess(int code , MiAccountInfo arg1)
{
switch( code )
{
case MiErrorCode.MI_XIAOMI_PAYMENT_SUCCESS:// 登陆成功
Log.i("Demo","小米登录成功");
//获取用户的登陆后的UID(即用户唯一标识)
String uid = arg1.getUid();
//以下为获取session并校验流程,如果是网络游戏必须校验,(12小时过期)
//获取用户的登陆的Session(请参考5.3.3流程校验Session有效性)
String session = arg1.getSessionId();
//请开发者完成将uid和session提交给开发者自己服务器进行session验证
Log.e("UserAgreed", "登陆成功");
JSONObject result3 = new JSONObject();
try {
result3.put("result", 1);
} catch (JSONException e) {
e.printStackTrace();
}
callback.onReceiveValue(result3);
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_LOGIN_FAIL:
loginFail(callback);
// 登陆失败
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_CANCEL:
loginFail(callback);
// 取消登录
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_ACTION_EXECUTED:
//登录操作正在进行中
break;
default:
// 登录失败
loginFail(callback);
break;
}
}
} );
}
public void loginFail(final ValueCallback callback){
Log.e("UserAgreed", "登陆失败");
JSONObject result = new JSONObject();
try {
result.put("result", 0);
} catch (JSONException e) {
e.printStackTrace();
}
callback.onReceiveValue(result);
}
(2)退出游戏:
MainActivity.java:
public void exitGame(){
MiCommplatform.getInstance().miAppExit( this, new OnExitListner()
{
@Override
public void onExit( int code )
{
Log.i("Demo","小米游戏退出");
if ( code == MiErrorCode.MI_XIAOMI_EXIT )
{
android.os.Process.killProcess( android.os.Process.myPid() );
}
}
} );
}
public void onUserAgreed(JSONObject jsonObj, final ValueCallback callback){
Log.d("UserAgreed", "Login info = " + jsonObj.toString());
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
/**
* 如果你的targetSDKVersion >= 23,就要主动申请好权限。如果您的App没有适配到Android6.0(即targetSDKVersion < 23),那么只需要在这里直接调用fetchSplashAd方法。
*
*/
checkAndRequestPermissions();
} else {
/**
* 如果是Android6.0以下的机器,默认在安装时获得了所有权限,可以直接调用SDK。
*/
}
MiCommplatform.getInstance().onUserAgreed(this);
MMApplication mApplication = (MMApplication) getApplication();
mApplication.initSDK(callback,this);
}
MMApplication.java中,但是联运SDK的初始化,还是应该在onCreate函数中调用才行,不然会无法运行apk
public void initSDK(final ValueCallback callback, MainActivity _mActivity){
mActivity =_mActivity;
MiCommplatform.getInstance().miLogin(mActivity,
new OnLoginProcessListener()
{
@Override
public void finishLoginProcess(int code , MiAccountInfo arg1)
{
switch( code )
{
case MiErrorCode.MI_XIAOMI_PAYMENT_SUCCESS:// 登陆成功
Log.i("Demo","小米登录成功");
//获取用户的登陆后的UID(即用户唯一标识)
String uid = arg1.getUid();
//以下为获取session并校验流程,如果是网络游戏必须校验,(12小时过期)
//获取用户的登陆的Session(请参考5.3.3流程校验Session有效性)
String session = arg1.getSessionId();
//请开发者完成将uid和session提交给开发者自己服务器进行session验证
Log.e("UserAgreed", "登陆成功");
JSONObject result3 = new JSONObject();
try {
result3.put("result", 1);
} catch (JSONException e) {
e.printStackTrace();
}
callback.onReceiveValue(result3);
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_LOGIN_FAIL:
mActivity.loginFail(callback);
// 登陆失败
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_CANCEL:
mActivity.loginFail(callback);
// 取消登录
break;
case MiErrorCode.MI_XIAOMI_PAYMENT_ERROR_ACTION_EXECUTED:
//登录操作正在进行中
break;
default:
// 登录失败
mActivity.loginFail(callback);
break;
}
}
} );
//广告sdk初始化
MiMoNewSdk.init(this, APPID, getString(R.string.app_name),
new MIMOAdSdkConfig.Builder()
.setDebug(false)
.setStaging(false).build(), new IMediationConfigInitListener() {
@Override
public void onSuccess() {
MLog.d(TAG, "mediation config init success");
mActivity.mProxy.InitAD();
}
@Override
public void onFailed(int errorCode) {
MLog.d(TAG, "mediation config init failed");
}
});
}
public class SecretUrlView {
private MainActivity mActivity;
private static String TAG = "SecretUrlView";
private View mView;
private WebView wv;
public SecretUrlView(MainActivity mActivity) {
this.mActivity = mActivity;
this.init();
}
public void init(){
mView = (ViewGroup) mActivity.urlView_container;
wv=(WebView)mView.findViewById(R.id.wv);
WebSettings ws=wv.getSettings();
ws.setJavaScriptEnabled(true);
wv.loadUrl("https://res.wqop2018.com//app/common/privacy.html");
wv.setWebViewClient(new WebViewClient());
mView.findViewById(R.id.view_url_close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mView.setVisibility(View.GONE);
}
});
mView.setVisibility(View.GONE);
}
public void showUrlView(){
mView.setVisibility(View.VISIBLE);
}
public void hideUrlView(){
mView.setVisibility(View.GONE);
}
}