以下代码对我来说很好。您可以随时向亚马逊的支持部门发送电子邮件,询问有关您的 IAP 提交失败的原因的详细信息。另外,发布您的代码,然后我们可以看到缺少的内容。当您在 Kindle 和其他 Android 设备(摩托罗拉 Droid、HTC 等)上进行测试时,您必须确保 IAP 正常工作或顺利退出。
private class AmazonPurchasingObserver extends BasePurchasingObserver
{
public AmazonPurchasingObserver()
{
super(oThis);
}
@Override
public void onItemDataResponse(ItemDataResponse itemDataResponse)
{
//Check itemDataResponse.getItemDataRequestStatus();
//Use itemDataResponse to populate catalog data
// Didn't use, items have already been stored locally in the game localization xml
}
@Override
public void onPurchaseResponse(PurchaseResponse purchaseResponse)
{
PurchaseRequestStatus status = purchaseResponse.getPurchaseRequestStatus();
Log.d(sTag, "status: " + status.name());
if (status == PurchaseRequestStatus.SUCCESSFUL)
{
//If SUCCESSFUL, fulfill content;
Receipt purchaseReceipt = purchaseResponse.getReceipt();
String sku = purchaseReceipt.getSku();
successBoughtProduct(sku); // implement the logic you need when a product is successfully bought, ie: increment game scores, save game states, etc.
Log.d(sTag, "SUCCESS: " + sku);
}
else
{
failToBuyProduct(); // implement your own logic to deal with failures
Log.d(sTag, "FAILED purchase");
}
}
}
public static void amazonPurchaseRequest(String productSku)
{
Log.d(sTag, "amazonPurchaseRequest: " + productSku);
PurchasingManager.initiatePurchaseRequest(productSku);
}
在您的 AndroidManifest.xml 中,在“应用程序”标签内,添加:
<application ... etc
<receiver android:name = "com.amazon.inapp.purchasing.ResponseReceiver" >
<intent-filter>
<action android:name = "com.amazon.inapp.purchasing.NOTIFY"
android:permission = "com.amazon.inapp.purchasing.Permission.NOTIFY" />
</intent-filter>
</receiver>
</application>