标签:android style blog http java color
原地址:http://blog.csdn.net/simdanfeg/article/details/9011863
上篇博文跟大家一起走了一遍支付宝支付,今天我们来看看移动支付。众所周知目前付费通道的龙头老大还要当属三大运营商(移动、联通、电信)。运营商接入代码相对简单,但琐碎的要求太多,涉及到启动界面、桌面图标、主界面、退出界面等。移动游戏基地后台地址:http://g.10086.cn/
部分截图
好了,继续贴代码:
AndroidManifest.xml配置:
MainActivity
package com.example.blogforyd; import cn.emagsoftware.gamebilling.api.GameInterface; import cn.emagsoftware.gamebilling.api.GameInterface.GameExitCallback; import android.os.Bundle; import android.app.Activity; import android.view.KeyEvent; import android.view.View; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 调用初始化移动支付,否则无法启动支付界面(此方法最好放到启动游戏的时候调用) GameInterface.initializeApp(this); findViewById(R.id.button1).setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Fiap fiap = new Fiap(MainActivity.this); // 需要购买什么道具传进去相应的index,此处传0为激活游戏 fiap.android_Pay(0); } }); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_BACK) { exit_game(); } return super.onKeyDown(keyCode, event); } // 退出游戏 public void exit_game() { GameInterface.exit(MainActivity.this, new GameExitCallback() { @Override public void onConfirmExit() { System.exit(0); } @Override public void onCancelExit() { } }); } // 是否开启音效 public boolean is_open_music() { return GameInterface.isMusicEnabled(); } }
Fiap.java
//移动支付 //2013-04-28 package com.example.blogforyd; import cn.emagsoftware.gamebilling.api.GameInterface; import cn.emagsoftware.gamebilling.api.GameInterface.BillingCallback; import android.app.Activity; import android.os.Handler; import android.os.Message; import android.util.Log; import android.widget.Toast; public class Fiap { private Activity mActivity; private boolean isRepeat; private String charge_Point; public Fiap(Activity activity){ mActivity = activity; } //index是三种计费点对应的标识 public void android_Pay(int index){ switch (index) { case 0: //激活游戏 isRepeat = false; //此处计费点填写移动平台申请的计费点的后三位作为计费点索引 charge_Point = "000"; break; case 1: isRepeat = true; charge_Point = "001"; break; case 2: isRepeat = true; charge_Point = "002"; break; case 3: isRepeat = true; charge_Point = "003"; break; default: break; } fiapHandler.sendEmptyMessage(1); } Handler fiapHandler = new Handler(){ public void handleMessage(Message msg) { if (msg.what == 1) { BillingCallback callBack = new BillingCallback() { @Override public void onBillingFail(String arg0) { // TODO Auto-generated method stub //此处表示支付失败 Log.i("result of pay", arg0); } @Override public void onBillingSuccess(String arg0) { // TODO Auto-generated method stub //此处为支付成功逻辑 Toast.makeText(mActivity, "支付成功", Toast.LENGTH_LONG).show(); } @Override public void onUserOperCancel(String arg0) { // TODO Auto-generated method stub //此处表示用户取消支付 Log.i("result of pay", arg0); } }; //第一个参数为:触发计费接口的Context对象 //第二个参数为:选择采用短信计费还是联网计费(true为短信,false为联网) //第三个参数为:计费点索引 //第四个参数为:支付结果回调 GameInterface.doBilling(mActivity, true, isRepeat, charge_Point,callBack); } }; }; }
至此移动计费接入就完成了
Android支付接入(二):移动游戏基地,布布扣,bubuko.com
标签:android style blog http java color
原文地址:http://www.cnblogs.com/123ing/p/3850454.html