In-app billing: SampleApplication and store data in the database
Can somebody please explain me why Android's sample application stores data in the database only in onRestoreTransactionsResponse
and not in onRequestPurchaseResponse
?
Since it is done so I am not sure how to test my application - if I use standard product ID (android.test.purchased), then onRestoreTransactionsResponse
is never called.
If I use my own product id - I am getting error that purchases are not allowed (my app is uploaded to Android Market, but not published; product id is published).
(My application will support one product only 开发者_如何学C- 'paid version of application', probably I should use some different from the sample application approach?)
The explanation is available at PurchaseObserver file coming with Sample Application - onRequestPurchaseResponse:
/**
* This is called when we receive a response code from Market for a
* RequestPurchase request that we made. This is NOT used for any
* purchase state changes. All purchase state changes are received in
* {@link #onPurchaseStateChange(PurchaseState, String, int, long)}.
* This is used for reporting various errors, or if the user backed out
* and didn't purchase the item. The possible response codes are:
* RESULT_OK means that the order was sent successfully to the server.
* The onPurchaseStateChange() will be invoked later (with a
* purchase state of PURCHASED or CANCELED) when the order is
* charged or canceled. This response code can also happen if an
* order for a Market-managed item was already sent to the server.
* RESULT_USER_CANCELED means that the user didn't buy the item.
* RESULT_SERVICE_UNAVAILABLE means that we couldn't connect to the
* Android Market server (for example if the data connection is down).
* RESULT_BILLING_UNAVAILABLE means that in-app billing is not
* supported yet.
* RESULT_ITEM_UNAVAILABLE means that the item this app offered for
* sale does not exist (or is not published) in the server-side
* catalog.
* RESULT_ERROR is used for any other errors (such as a server error).
onRestoreTransactionsResponse is just about response to our request (not purchase status):
/**
* This is called when we receive a response code from Android Market for a
* RestoreTransactions request that we made. A response code of
* RESULT_OK means that the request was successfully sent to the server.
*/
If I call onRestoreTransactionsResponse, then onRequestPurchaseResponse is also called.
One thing to know, to be able to test your own items you have to create a signed apk of you app and install it manually on your device (it was working for me that way, otherwise I had the same error you had)
I hope it helps!
精彩评论