我對Android應用程序的工作,允許非消耗應用內購買(用戶只需購買功能一次,然後他們可以訪問(帶單聲道/ Xamarin實現)它永遠跨越所有設備)。我正在嘗試使用Xamarin.InAppBilling組件來實現這一點。Xamarin.InAppBilling - OnProductPurchase OnProductPurchasedError事件
根據對Xamarin.InAppBilling組件(http://components.xamarin.com/view/xamarin.inappbilling)的文件,這些事件對我的使用存在:
Xamarin.InAppBilling定義了以下事件,您可以 監測和應對:
OnConnected - 組件附加到Google Play時引發。
OnDisconnected - 在組件從谷歌播放分離引發。
OnInAppBillingError - 在組件內發生錯誤時引發。
OnProductPurchasedError - 當有錯誤購買產品或訂閱引發。 >
OnProductPurchase - 產品成功購買時產生。
OnPurchaseConsumedError - 當有錯誤消費購買引發。
OnPurchaseConsumed - 購買成功消耗時產生。
我看到定義爲Xamarin.InAppBilling.InAppBillingServiceConnection類的一部分的OnConnected,OnDisconnected和OnInAppBillingError事件。
在程序集瀏覽器中,我發現其他事件定義爲Xamarin.InAppBilling.InAppBillingHandler類的一部分,但我不確定訪問它們的最佳方式,因爲它們不通過IInAppBillingHandler接口可用。通過屬性Xamarin.InAppBilling.InAppBillingServiceConnection.BillingHandler訪問它們是有意義的,但是該屬性返回的實例是IInAppBillingHandler而不是InAppBillingHandler類。
我的問題:
我應該想到這個代碼工作的在線評論請注意它應注意什麼?
// When activity starts...
_serviceConnection = new InAppBillingServiceConnection (CurrentContext, publicKey);
_serviceConnection.OnConnected +=() =>
{
var bh = _serviceConnection.BillingHandler as InAppBillingHandler;
bh.OnProductPurchased += (sku) => {
// This code should run when call to BuyProduct is successful
var purchasedProductId = sku;
};
bh.OnProductPurchasedError += (int responseCode, string sku) => {
// This code should run when call to BuyProduct is NOT successful
var p = sku;
Toast.MakeText(this, "KP - purchase error: " + p, ToastLength.Long).Show();
};
};
// When "Buy" button is clicked. Expect OnProductPurchasedError or OnProductPurchased to be called as a result of a call to this
_serviceConnection.BillingHandler.BuyProduct(_selectedProduct);
我做了一個測試通過修改示例代碼包含在加入我上面的代碼,並在OnProductPurchasedError事件似乎經常提出的(通常右邊前的谷歌遊戲UI說,購買成功)的組件。即使Google Play用戶界面顯示成功的交易,我也沒有看到OnProductPurchased事件處理程序被調用。有時會在顯示Google Play用戶界面之前調用此事件,以便用戶輸入付款方式。
我的期望是,只要購買成功完成勾搭成OnProductPurchased的事件處理程序將被調用。然而,這似乎並沒有發生,我找不到任何這些事件的文檔(除了我在這裏粘貼的)。此外,傳遞給OnProductPurchasedError事件處理程序的響應代碼始終爲0。
正如我已經做了研究發佈這個問題,我目前的理論是,這些事件不工作,因爲我期望和文檔是不正確的。
注意:我使用android.test.purchased作爲產品ID。我在重新測試之前正在使用購買產品,我假設它將其重置爲非購買狀態。
有沒有人成功地使用過這些事件?