次のコードは私にとってはうまく機能します。いつでもAmazonのサポートに電子メールを送信して、IAPが送信に失敗した理由の詳細を尋ねることができます。また、コードを投稿すると、不足しているものを確認できます。Kindleやその他のAndroidデバイス(Motorola 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」タグ内に次を追加します。
<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>