【发布时间】:2014-06-11 09:06:05
【问题描述】:
我按照此文档http://developer.android.com/google/play/billing/billing_integrate.html 创建了一个测试应用程序,该应用程序在单击按钮后启动应用内购买程序。
我将应用程序发布为 alpha 版本并测试了应用内购买,它可以正常工作。
我的问题是,我对其他应用内购买示例感到困惑。他们都使用一个名为“IabHelper”的类来进行应用内购买。 但似乎不需要这个类来进行应用内购买。 该类甚至在官方 In-App-Billing V3 “TrivalDrive” 示例中使用,但在我上面发布的应用内计费指南中从未提及。
那么有人可以向我解释一下,为什么以及何时应该使用 IabHelper 类?
提前谢谢你。
这是我用来进行应用内购买的代码的简化版本:
private void doPurchase() {
try {
Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), "premium.upgrade",
"inapp", "");
if (buyIntentBundle != null && buyIntentBundle.getInt("RESPONSE_CODE") == 0) {
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(),
Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
}
} catch (SendIntentException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
if (resultCode == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString("productId");
Log.i(">>>", "You have bought the "
+ sku
+ ". Excellent choice, "
+ "adventurer!");
} catch (JSONException e) {
Log.e(">>>", "Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
【问题讨论】:
标签: android in-app-purchase in-app-billing