应用内结算:SampleApplication并将数据存储在数据库中

时间:2011-04-10 10:33:20

标签: android in-app-purchase google-play

有人可以解释一下,为什么Android sample application仅在onRestoreTransactionsResponse而不是onRequestPurchaseResponse中将数据存储在数据库中?

由于它已经完成所以我不确定如何测试我的应用程序 - 如果我使用standard product ID(android.test.purchased),则永远不会调用onRestoreTransactionsResponse。 如果我使用自己的产品ID - 我收到的错误是不允许购买(我的应用程序已上传到Android电子市场,但尚未发布;产品ID已发布)。

(我的应用程序仅支持一种产品 - “应用程序的付费版本”,可能我应该使用与示例应用程序方法不同的一些产品?)

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

有一件事要知道,为了能够测试你自己的项目,你必须创建一个你的应用程序的签名apk并在你的设备上手动安装(这对我有用,否则我有同样的错误你有)

我希望它有所帮助!