我按照這個文檔http://developer.android.com/google/play/billing/billing_integrate.html來創建一個測試應用程序,它在點擊一個按鈕後啓動一個應用程序內購買程序。
我發佈了應用程序作爲alpha版本,並測試了應用程序內購買,它的工作原理。我什麼時候需要IabHelper類來進行InApp購買?
我的問題是,我感到困惑其他應用程序內購買的例子。他們都使用名爲「IabHelper」的類來進行應用內購買。 但是,似乎並不需要這個類來進行應用內購買。 該課程甚至在官方應用內結賬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();
}
}
}
}
當。 Google甚至無法寫出無bug的應用程序內購買實現,這是非常可悲的。 – trans
@trans是的,它有點奇怪,因爲它是平臺的基礎部分。不過,我一直在使用名爲[Checkout]的庫(https://github.com/serso/android-checkout)很長一段時間沒有遇到任何明顯的問題。我強烈推薦它適用於IAB相關的所有內容。 – reVerse