You can now use this Market Billing Service reference to make billing request calls using the send- BillingRequest method. Note that this must be performed on the main application thread.To make a billing request, you must pass in a Bundle parameter that specifies the type of transac¬tion you want to execute, the version of the IAB API you are using, your package name, and the product ID to be purchased, as shown in Listing 18-11. The following five billing request types are supported:^ request_purchase — Initiates a purchase request.^ check_billing_supported — Verifies that IAB is supported on the host device.^ get_purchase_information — Requests the transaction information for a prior purchase or a refund.^ confirm_notifications — Acknowledges the receipt of the transaction information related to a purchase or refund.^ restore_transactions — Retrieves a user’s transaction history for his or her managed purchases.To initiate the billing request, call the Market Billing Service’s sendBillingRequest method, pass¬ing in the Bundle:Bundle response = billingService.sendBillingRequest(request);The sendBillingRequest method will return a Bundle response that contains a response code, request ID, and a Pending Intent that you use to launch the checkout UI.Handling In-App Billing Purchase Request ResponsesWhen your billing request type is REQUEST_PURCHASE, your application must listen for two Broadcast Intents — one containing a response code and another containing an IAB notification — to determine the success of your attempted transaction:
After the Market Billing Service successfully receives your billing request, it broadcasts a response_ code Intent whose result is set to result_ok.
When the transaction itself has been executed, the Market Billing Service broadcasts an IN_ app_notify Intent. This Broadcast Intent contains a notification ID that, along with a nonce, is used to retrieve the purchase information for a given purchase request using the get_purchase_ information request type.
Making a purchase information request returns a Bundle containing a response code and request ID, as well as triggering two further asynchronous Broadcasts Intents. The first, a response_code Intent, returns the success and error status associated with your purchase request, using the nonce you specified in the request as an identifier.
If the purchase is successful, a purchase_state_changed broadcast will also be broadcast, contain¬ing detailed transaction information as a signed JSON string.
USING WAKE LOCKS
In order to prolong battery life, when an Android device is left idle, it will first dim, then turn off the screen, and, finally, turn off the CPU.
đang được dịch, vui lòng đợi..