The call back method onPurchaseStateChange
is never called. I did my own demo-app and also tried using the Google provided demo (Dungeons).
I'm calling requestPurchase(String productId, String payload)
from the onClick
method.
@Override
public void onClick(View view) {
if(view == requestPurchaseButton) {
mBillingService.requestPurchase("android.test.purchased", "10");
}
}
The callback method onRequestPurchaseResponse(Request, ResponseCode)
is called.
The responseCode
here gives the value RESULT_OK
. So the request has been sent to the server.
@Override
public void onRequestPurchaseResponse(RequestPurchase request,
ResponseCode responseCode)
{
if(responseCode == ResponseCode.RESULT_OK) {
Log.d("AJ", "onRequestPurchaseResponse.ResponeCode.RESULT_OK");
textView.append(request.mProductId + "\n");
} else if(responseCode == ResponseCode.RESULT_USER_CANCELED) {
//doesn't go here
} else {
//doesn't go here
}
}
The javadoc for this method states
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 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).
But the callback method
@Override
public void onPurchaseStateChange(PurchaseState purchaseState,
String itemId, int quantity, long purchaseTime,
String developerPayload) {
Log.d("AJ", "onPurchaseStateChanged");
}
is never called.
Am I missing something? The same thing is being done in Dungeons (Google provided demo) and the onPurchaseStateChange
is not called.
The Test-InAppBilling document shows that we must be able to reach Purchased state. But When I try, I see only
android.test.purchased: sending purchase request.
I was having this same problem but just solved it for myself. I was using my work's public key in the code, but trying to run the app on my personal phone. Since I was signed in on my phone with my personal account, I'm guessing Google rightly assumed I wasn't the developer. I would think they would send an error message back though. Once I plugged my personal key into the code, it worked fine on my phone. So the key's may not be matching for you as well.