您好,我已经使用 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
中实现了逻辑来更新 UI if bp.isSubscribed(SUBSCRIPTION_ID)
返回 true
。请告诉我如何获取订阅开始日期和到期日期。
最佳答案
我想给自己问题的答案一个答案,这样如果有人寻找同样的答案就可以找到解决方案。
经过大量谷歌我没有找到我正在寻找的确切解决方案所以我在 iabv3 library
项目的 BillingProcessor
类中创建了一个方法,它返回一个 Bundle
带有购买详细信息,我在其中获取购买日期。现在我可以找到到期日了。该方法如下所示
public Bundle getPurchases(){
if (!isInitialized())
return null;
try{
return billingService.getPurchases(Constants.GOOGLE_API_VERSION, contextPackageName, Constants.PRODUCT_TYPE_SUBSCRIPTION, null);
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
关于android - 如何在inapp v3 android中获取订阅到期日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30620506/