嗨,我已经使用android-inapp-billing-v3为项目实施了一年的inapp计费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)
返回则更新UI的逻辑true
。请告诉我如何获取订阅的起始日期和到期日期。
我想将Ans赋予我自己的问题,以便有人寻找相同的答案。经过大量的谷歌搜索后,我没有找到确切的解决方案,所以我BillingProcessor
在iabv3 library
项目中的类中创建了一个方法,该方法返回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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句