LG U+ 인앱 결제 라이브러리 예제이다. LG U+의 공식 예제에는 액티비티를 상속받게 되어 있는데 상속 안받는 버전으로 변경해 보았다.
package com.example.lgtsample;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.feelingk.lguiab.LguIAPLib;
import com.feelingk.lguiab.LguIAPLib.OnClientListener;
import com.feelingk.lguiab.vo.IAPLibSetting;
import com.feelingk.lguiab.vo.ProductItemInfo;
import com.feelingk.lguiab.vo.UseItemInfo;
//public class MainActivity extends LguIAPLib {
public class MainActivity extends Activity {
/** IAP Library Init */
private LguIAPLib mIAPLib = null;
private IAPLibSetting setting = null;
private final String lgt_aid = "Q0201083****";
private String mTestAppID = "Q0201083****"; // AppID (개발)
private String mTestPID = "Q02D1083****"; // PID
private String mTestBpIP = null; // BPIP
private String mTestBpPort = "0"; // BPPort
private String mTestBpUri = null; // BPUri
private String mTestBpData = null; // BPData
private boolean serverType = false; // false: 개발기, true: 상용
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mIAPLib = new LguIAPLib();
initLGTStore();
Button payment = (Button) findViewById(R.id.payment);
payment.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// lguIABpopPurchaseDlg(MainActivity.this, lgt_aid,
// "Q02D10830139", null, null, setting);
mIAPLib.lguIABpopPurchaseDlg(MainActivity.this, mTestAppID, mTestPID,
mTestBpUri, mTestBpData, setting);
}
});
}
private OnClientListener mClientListener = new OnClientListener() {
private static final int LGT_BUY_STATE_OK = 0;
private static final int LGT_BUY_STATE_CANCEL = 1;
private static final int LGT_BUY_STATE_ERROR = 2;
private int mState = LGT_BUY_STATE_CANCEL;
@Override
public void lguIABonBuyVerifyComplete(String arg0, String arg1) {
// TODO Auto-generated method stub
}
@Override
public void lguIABonDlgClick() {
// TODO Auto-generated method stub
// OK, ERROR
switch (mState) {
case LGT_BUY_STATE_OK:
// CletActivity.handleSendBuyEvent(M_E_SUCCESS, 0);
break;
case LGT_BUY_STATE_ERROR:
// CletActivity.handleSendBuyEvent(M_E_ERROR, 0);
break;
}
}
@Override
public void lguIABonDlgPurchaseCancel() {
// TODO Auto-generated method stub
mState = LGT_BUY_STATE_CANCEL;
// CletActivity
// .handleSendBuyEvent(M_E_PAYMENT_CANCELED, 0);
}
@Override
public void lguIABonError(int arg0, int arg1) {
// TODO Auto-generated method stub
mState = LGT_BUY_STATE_ERROR;
// 다음에 DlgClick이 불림
}
@Override
public void lguIABonItemAuthInfo(ProductItemInfo arg0) {
// TODO Auto-generated method stub
}
@Override
public void lguIABonItemPurchaseComplete(String arg0, String arg1) {
// TODO Auto-generated method stub
mState = LGT_BUY_STATE_OK;
}
@Override
public boolean lguIABonItemQueryComplete() {
// TODO Auto-generated method stub
// 이게 true여야 함
return true;
}
@Override
public void lguIABonItemUseQuery(UseItemInfo arg0) {
// TODO Auto-generated method stub
}
@Override
public void lguIABonWholeQuery(List<ProductItemInfo> arg0) {
// TODO Auto-generated method stub
}
};
private void initLGTStore() {
// 라이브러리 설정
setting = new IAPLibSetting(this, mTestAppID, mTestBpIP, mTestBpPort,
serverType, mClientListener);
mIAPLib.LguIAPLibInit(setting);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
No comments:
Post a Comment