我正在为黑莓应用内计费开发 Android 运行时,它们支持 Google 应用内计费版本 2,所以我需要使用版本 2 而不是版本 3。
我的项目是管理的。
我坚持测试恢复事务部分。
1)如何测试它?
2)我们可以用“android.test.purchased”进行测试,如果可以的话怎么做?
3)恢复交易(已经购买的物品)的流程如何?
4)根据我的理解 onPurchaseStateChange 在我们请求购买和恢复购买的物品时调用一次。我的理解正确吗?
我查看了官方开发者网站,但我有点困惑。
这是我被卡住的主要代码部分。
private class DungeonsPurchaseObserver extends PurchaseObserver {
public DungeonsPurchaseObserver(Handler handler) {
super(BlackBerryInAppPurchaseActivity.this, handler);
}
@Override
public void onBillingSupported(boolean supported, String type) {
if (Consts.DEBUG) {
Log.i(TAG, "supported: " + supported);
}
Toast.makeText(getApplicationContext(), " billing supported: " + supported, 2000).show();
if (type == null || type.equals(Consts.ITEM_TYPE_INAPP)) {
if (supported) {
restoreDatabase();
} else {
showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
}
} else {
showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
}
}
@Override
public void onPurchaseStateChange(PurchaseState purchaseState, String itemId, int quantity, long purchaseTime, String developerPayload) {
if (Consts.DEBUG) {
Log.i(TAG, "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState);
}
Toast.makeText(getApplicationContext(), "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState, 2000).show();
if (purchaseState == PurchaseState.PURCHASED) {
//Update the UI -unlock app
updateUI();
Toast.makeText(getApplicationContext(), "Purchased Update the Ui " + purchaseState, 2000).show();
mOwnedItems.add(itemId);
//Toast.makeText(getApplicationContext(), "Hiding the button as the item is purchased " + itemId + " " + purchaseState, 2000).show();
}
//mOwnedItemsCursor.requery();
Toast.makeText(getApplicationContext(), "SKU IS " + mSku, 2000).show();
if (itemId.equals(mSku)) {
switch (purchaseState) {
case PURCHASED:
Toast.makeText(getApplicationContext(), " Purchased itemId: " + itemId + " " + purchaseState, 2000).show();
break;
default:
Toast.makeText(getApplicationContext(), " Item NOT Purchased itemId: " + itemId + " " + purchaseState, 2000).show();
break;
}
}
}
@Override
public void onRequestPurchaseResponse(RequestPurchase request, ResponseCode responseCode) {
if (Consts.DEBUG) {
Log.d(TAG, request.mProductId + ": " + responseCode);
}
// Toast.makeText(getApplicationContext(), "request.mProductId " + responseCode, 2000).show();
if (responseCode == ResponseCode.RESULT_OK) {
if (Consts.DEBUG) {
Log.i(TAG, "purchase was successfully sent to server");
}
Toast.makeText(getApplicationContext(), "purchase was successfully sent to server" + responseCode, 2000).show();
logProductActivity(request.mProductId, "sending purchase request");
} else if (responseCode == ResponseCode.RESULT_USER_CANCELED) {
if (Consts.DEBUG) {
Log.i(TAG, "user canceled purchase");
}
logProductActivity(request.mProductId, "dismissed purchase dialog");
} else {
if (Consts.DEBUG) {
Log.i(TAG, "purchase failed");
}
Toast.makeText(getApplicationContext(), "purchase failed" + responseCode, 2000).show();
logProductActivity(request.mProductId, "request purchase returned " + responseCode);
}
}
@Override
public void onRestoreTransactionsResponse(RestoreTransactions request, ResponseCode responseCode) {
if (responseCode == ResponseCode.RESULT_OK) {
if (Consts.DEBUG) {
Log.d(TAG, "completed RestoreTransactions request");
}
Toast.makeText(getApplicationContext(), "completed RestoreTransactions request " + responseCode, 2000).show();
// Update the shared preferences so that we don't perform
// a RestoreTransactions again.
SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor edit = prefs.edit();
edit.putBoolean(DB_INITIALIZED, true);
edit.commit();
} else {
if (Consts.DEBUG) {
Log.d(TAG, "RestoreTransactions error: " + responseCode);
}
Toast.makeText(getApplicationContext(), "RestoreTransactions error: " + responseCode, 2000).show();
}
}
}