【问题标题】:In-app billing: SampleApplication and store data in the database应用内计费:SampleApplication 并将数据存储在数据库中
【发布时间】:2011-04-10 10:33:20
【问题描述】:
谁能解释一下为什么Android的sample application只在onRestoreTransactionsResponse而不是onRequestPurchaseResponse将数据存储在数据库中?
既然完成了,我不确定如何测试我的应用程序 - 如果我使用 standard product ID (android.test.purchased),那么永远不会调用 onRestoreTransactionsResponse。
如果我使用自己的产品 ID - 我收到不允许购买的错误消息(我的应用已上传到 Android Market,但未发布;产品 ID 已发布)。
(我的应用程序将仅支持一种产品 - '付费版本的应用程序',也许我应该使用一些与示例应用程序不同的方法?)
【问题讨论】:
标签:
android
in-app-purchase
google-play
【解决方案1】:
示例应用程序随附的 PurchaseObserver 文件中提供了说明 -
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 只是对我们请求的响应(不是购买状态):
/**
* 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.
*/
如果我调用 onRestoreTransactionsResponse,那么 onRequestPurchaseResponse 也会被调用。
【解决方案2】:
有一点要知道,为了能够测试您自己的项目,您必须为您的应用创建一个签名的 apk 并在您的设备上手动安装(它对我有用,否则我遇到了与您相同的错误)
希望对你有帮助!