此處我正在實施Google的多種訂閱類型的應用內購買,即monthly
,quarterly
,half-yearly
和yearly
。 我爲每個訂閱類型創建SkewId
而不是託管或非託管。這些訂閱包將適用於相同類型的工作。但是現在我想知道怎麼才能知道訂閱的日子,付款後打包訂閱?針對同一類型產品的多種訂閱的Android應用內購買
我實現代碼託管類型爲:
mHelper = new IabHelper(this, base64EncodedPublicKey);
// enable debug logging (for a production application, you should set
// this to false).
mHelper.enableDebugLogging(true);
mHelper.startSetup(new
IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d("TAG", "In-app Billing setup failed: " +
result);
} else {
Log.d("TAG", "In-app Billing is set up OK");
}
}
});
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase) {
if (result.isFailure()) {
// Handle error
Log.d("TAG", "We have gas. Consuming it.");
remove_ads_btn_monthly.setEnabled(true);
remove_ads_btn_quarterly.setEnabled(true);
remove_ads_btn_halfyearly.setEnabled(true);
remove_ads_btn_yearly.setEnabled(true);
if (plan_duration != 1)
toast = new CustomToast(RemoveAdsActivity.this, "You've already subscribed package of " + plan_duration + " months.");
else
toast = new CustomToast(RemoveAdsActivity.this, "You've already subscribed package of " + plan_duration + " month.");
return;
} else if (purchase.getSku().equals(SKU_MONTHLY)) {
consumeItem();
remove_ads_btn_monthly.setEnabled(false);
remove_ads_btn_quarterly.setEnabled(false);
remove_ads_btn_halfyearly.setEnabled(false);
remove_ads_btn_yearly.setEnabled(false);
} else if (purchase.getSku().equals(SKU_HALF_YEARLY)) {
consumeItem();
remove_ads_btn_monthly.setEnabled(false);
remove_ads_btn_quarterly.setEnabled(false);
remove_ads_btn_halfyearly.setEnabled(false);
remove_ads_btn_yearly.setEnabled(false);
} else if (purchase.getSku().equals(SKU_QUARTERLY)) {
consumeItem();
remove_ads_btn_monthly.setEnabled(false);
remove_ads_btn_quarterly.setEnabled(false);
remove_ads_btn_halfyearly.setEnabled(false);
remove_ads_btn_yearly.setEnabled(false);
} else if (purchase.getSku().equals(SKU_ANNUALY)) {
consumeItem();
remove_ads_btn_monthly.setEnabled(false);
remove_ads_btn_quarterly.setEnabled(false);
remove_ads_btn_halfyearly.setEnabled(false);
remove_ads_btn_yearly.setEnabled(false);
}
}
};
public void consumeItem() {
mHelper.queryInventoryAsync(mReceivedInventoryListener);
}
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
Purchase gasMonthly = inventory.getPurchase(SKU_MONTHLY);
Purchase gasYearly = inventory.getPurchase(SKU_ANNUALY);
Purchase gasQuarterly = inventory.getPurchase(SKU_QUARTERLY);
Purchase gasHalfYearly = inventory.getPurchase(SKU_HALF_YEARLY);
if (gasMonthly != null) {
mHelper.consumeAsync(inventory.getPurchase(SKU_MONTHLY), mConsumeFinishedListener);
mSubscribedTo = true;
} else if (gasYearly != null) {
mHelper.consumeAsync(inventory.getPurchase(SKU_ANNUALY), mConsumeFinishedListener);
mSubscribedTo = true;
} else if (gasQuarterly != null) {
mHelper.consumeAsync(inventory.getPurchase(SKU_QUARTERLY), mConsumeFinishedListener);
mSubscribedTo = true;
} else if (gasHalfYearly != null) {
mHelper.consumeAsync(inventory.getPurchase(SKU_HALF_YEARLY), mConsumeFinishedListener);
mSubscribedTo = true;
} else {
mSubscribedTo = false;
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase,
IabResult result) {
if (result.isSuccess()) {
//API
remove_ads_btn_monthly.setEnabled(true);
remove_ads_btn_quarterly.setEnabled(true);
remove_ads_btn_halfyearly.setEnabled(true);
remove_ads_btn_yearly.setEnabled(true);
} else {
// handle error
}
}
};
現在,我想知道我怎麼可以自定義我的代碼支付每類申購的,如圖中的圖像。每個訂閱應該在時間段結束後自動激活。
謝謝。
consumeAsync訂閱?沒辦法,你不應該使用。請閱讀文件。訂閱是不消費的 –
我在上面提到我實現了這個託管產品。 – Siri