【发布时间】:2015-08-17 16:29:48
【问题描述】:
您好,我已经使用 android-inapp-billing-v3 为一个项目实施了一年订阅的应用内计费 V3。我想在我的应用程序中显示剩余天数。我打电话给getSubscriptionTransactionDetails 来获取产品的交易详情,但它总是返回null。这是我的代码。
private BillingProcessor startInappCheck(){
bp = new BillingProcessor(mContext, BASE64ENCODEDPUBLICKEY, new BillingProcessor.IBillingHandler() {
@Override
public void onProductPurchased(String productId, TransactionDetails details) {
LogUtils.e(TAG, "onProductPurchased :" +productId);
// showToast("onProductPurchased: " + productId);
}
@Override
public void onBillingError(int errorCode, Throwable error) {
LogUtils.e(TAG, "onBillingError :" +errorCode);
}
@Override
public void onBillingInitialized() {
// showToast("onBillingInitialized");
readyToPurchase = true;
try{
SkuDetails subs = bp.getSubscriptionListingDetails(SUBSCRIPTION_ID);
LogUtils.d(TAG, "Owned Subscription: " + subs.toString());
TransactionDetails tr = bp.getSubscriptionTransactionDetails(SUBSCRIPTION_ID);
LogUtils.d(TAG, "Owned Subscription: " + tr.toString());
}catch (Exception e) {
// TODO: handle exception
}
}
@Override
public void onPurchaseHistoryRestored() {
// showToast("onPurchaseHistoryRestored");
for(String sku : bp.listOwnedSubscriptions()){
LogUtils.d(TAG, "Owned Subscription: " + sku);
}
// showToast("onPurchaseHistoryRestored");
}
});
return bp;
}
我从onCreate调用了这个方法。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (!bp.handleActivityResult(requestCode, resultCode, data))
super.onActivityResult(requestCode, resultCode, data);
}
我的订阅项目按钮在 fragment 中实现。还有一个问题,我发现在成功订阅后onProductPurchased 不会被调用,但我已经在onResume 中实现了逻辑,以在bp.isSubscribed(SUBSCRIPTION_ID) 返回true 时更新UI。请告诉我如何获取订阅开始日期和到期日期。
【问题讨论】:
-
订阅后获取订阅到期日期。参考这个链接:stackoverflow.com/questions/38800937/…
标签: android in-app-purchase in-app-billing in-app-subscription