UC SDK的问题之前已经说明:
今天把版本发给UC 的时候 那边看到我把所有SDK的界面都给横屏了 表示不能通过。
也就是说。必须竖屏!!! 没办法 不竖屏硬是不给发布。
那怎么办呢??追根溯源。这个问题就是由于AndroidSDK在横竖屏切换时,activity被销毁
但是设置
[code lang=”java”]android:configChanges="orientation|keyboardHidden|screenSize"[/code]
属性并不能解决问题 这可能是和GPU渲染的特性有关。
也就是说 对于 主游戏启用GPU的activity 不能横竖屏切换。知道这一点那就好办了。
那我们传一个自己新建的activity给SDK就可以解决问题了。
我们新建一个activity 然后在支付 和其他界面的时候 把这个activity传给它。
具体类如下:
[code lang=”java”]
package cn.uc.gamesdk.view;
import org.json.JSONObject;
import cn.uc.gamesdk.UCCallbackListener;
import cn.uc.gamesdk.UCGameSDK;
import cn.uc.gamesdk.UCGameSDKStatusCode;
import cn.uc.gamesdk.info.OrderInfo;
import cn.uc.gamesdk.info.PaymentInfo;
import com.adobe.fre.FREContext;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
* @author Rect
* @version Time:2013-5-31
*/
public class XmshBridgeActiviey extends Activity implements OnClickListener
{
//声明开启Activity的Action
public static final String MYACTIVITY_ACTION = "cn.uc.gamesdk.view.XmshBridgeActiviey";
private String TAG = "XmshBridgeActiviey";
private LinearLayout layout;
public static FREContext _context;
public static int selectKey = 0;
public static PaymentInfo payInfo;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
//构建界面
Log.d(TAG, "———onCreate——-");
super.onCreate(savedInstanceState);
Log.d(TAG, "———getResourceId–2—–");
// 隐藏标题栏
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// 隐藏状态栏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setBackgroundResource(_context.getResourceId("drawable.bg"));
this.setContentView(layout);
TextView textv = new TextView(this);
String str_2 = "跳转验证!点击任意返回游戏….";
textv.setText(str_2);
layout.addView(textv);
layout.setId(1);
layout.setOnClickListener(this);
switch(selectKey)
{
case 0:
Log.d(TAG, "UCFEnterUserCenter calling…");
try {
UCGameSDK.defaultSDK().enterUserCenter(this.getApplicationContext(), new Listener(_context).userCenterListener);
} catch (Exception e) {
e.printStackTrace();
}
break;
default:
Log.d(TAG, "paypaypaypaypaypaypay…");
try {
UCGameSDK.defaultSDK().pay(_context.getActivity().getApplicationContext(), payInfo,
new Listener(_context).orderResultListener);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
private class Listener {
private FREContext context;
public Listener(FREContext context) {
this.context = context;
}
public UCCallbackListener userCenterListener = new UCCallbackListener() {
@Override
public void callback(int code, String data) {
Log.d(TAG, "Received user center notification: code=" + code + ", data=" + data);
String msg = null;
switch (code) {
case UCGameSDKStatusCode.SUCCESS:
msg = "九游社区正常退出";
break;
case UCGameSDKStatusCode.NO_INIT:
msg = "调用九游社区失败,没有初始化";
break;
case UCGameSDKStatusCode.NO_LOGIN:
msg = "调用九游社区失败,没有登录";
break;
default:
msg = "";
break;
}
try{
JSONObject jobj = new JSONObject();
jobj.put("callbackType", "EnterUserCenter");
jobj.put("code", code);
jobj.put("data", msg);
if (_context != null) {
_context.dispatchStatusEventAsync(jobj.toString(), "");
} else {
Log.d(TAG, "dispatchStatusEventAsync canceled: context is null");
}
} catch (Throwable e) {
Log.e(TAG, "", e);
}
}
};
public UCCallbackListener orderResultListener = new UCCallbackListener() {
@Override
public void callback(int code, OrderInfo orderInfo) {
String text = null;
switch (code) {
case UCGameSDKStatusCode.SUCCESS:
if (orderInfo != null) {
String orderId = orderInfo.getOrderId();
float amount = orderInfo.getOrderAmount();
int payway = orderInfo.getPayWay();
String paywayName = orderInfo.getPayWayName();
text = "Order Result: OrderId=" + orderId + ", Amount=" + amount + ", PayWayId=" + payway + ", PayWayName=" + paywayName;
Log.d(TAG, text);
text = null;
//
} else {
Log.e(TAG, "Received empty order result");
}
break;
case UCGameSDKStatusCode.NO_INIT:
text = "Paying failed: no init";
Log.e(TAG, text);
break;
case UCGameSDKStatusCode.PAY_USER_EXIT:
text = "User exit the paying page, return to game page.";
Log.d(TAG, text);
break;
default:
text = "Unknown paying result code: code=" + code;
Log.e(TAG, text);
break;
}
try {
JSONObject jobj = new JSONObject();
jobj.put("callbackType", "Pay");
jobj.put("code", code);
if (orderInfo == null) {
jobj.put("data", null);
} else {
JSONObject jdata = new JSONObject();
jdata.put("orderId", orderInfo.getOrderId());
jdata.put("orderAmount", orderInfo.getOrderAmount());
jdata.put("payWay", orderInfo.getPayWay());
jdata.put("payWayName", orderInfo.getPayWayName());
jobj.put("data", jdata);
}
if (context != null) {
context.dispatchStatusEventAsync(jobj.toString(), "");
} else {
Log.d(TAG, "dispatchStatusEventAsync canceled: context is null");
}
} catch (Throwable e) {
Log.e(TAG, "", e);
}
}
};
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case 1:
Log.d(TAG, "———退出——-");
XmshBridgeActiviey.this.finish();
selectKey = 0;
break;
case 3:
break;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK )
{
selectKey = 0;
}
return super.onKeyDown(keyCode, event);
}
}
[/code]
我们在主游戏的 XXX-app.xml中加入声明:
然后在支付 或者9游中心的打开函数中如此调用startActiviry
[code lang=”java”]
Log.d(TAG, "—-UCFPay—–Intent处理——-");
XmshBridgeActiviey.selectKey = 1;
Intent intent = new Intent(XmshBridgeActiviey.MYACTIVITY_ACTION);
context.getActivity().startActivityForResult(intent, 0);
Log.d(TAG, "—-UCFPay—–start处理——-");[/code]
这样传给SDK的activity就不是游戏的主activity了。
横竖屏切换 也就跟主游戏的activity无关了。
这样就能保持可爱的UC 一直竖屏下去了。。请你一直竖屏下去吧 不要让我看到你横屏的那一天~
接完sdk,系统的看了一下大神的ane篇,这篇真心笑了!