问题描述
您好我已经使用。我想在我的应用中显示剩余的日子。我正在调用 getSubscriptionTransactionDetails
来获取产品的交易详情,但它总是返回 null
。这是我的代码。
Hi I have I implemented inapp billing V3 for one year subscription for a item using android-inapp-billing-v3. I want to show remaining days in my app. I am calling getSubscriptionTransactionDetails
to get Transaction details for the product but it always returns null
. here is my code.
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 $ c调用此方法$ c>。
@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);
}
我的订阅项按钮在片段。我发现另一个问题是,在成功订阅后, onProductPurchased
未被调用,但我已在 onResume
中实现逻辑以进行更新用户界面如果 bp.isSubscribed(返回
true
。请告诉我如何获得订阅发起日期和到期日期。
My subscription item button implemented in a fragment
. One more problem I found that after successful subscription the onProductPurchased
not get called but I have implemented the logic in onResume
to update UI if bp.isSubscribed(SUBSCRIPTION_ID)
returns true
. Please tell me how to get subscription initiated date and expiry date.
推荐答案
我想把Ans给我自己的问题,所以如果某人寻找相同的可以找到解决方案。
经过大量的谷歌我没有找到我想要的确切解决方案所以我在 iabv3库中的
BillingProcessor
类中创建了一个方法/ code>项目,返回 Bundle
,其中包含购买详细信息,其中我获得了购买日期。现在我可以找到这个到期日。该方法如下所示
I want to give Ans to my own que's ans, So that if some one looking for the same can find the solution. After lots of google I did not find a exact solution I was looking for So I create a method in BillingProcessor
class in iabv3 library
project which returns a Bundle
with Purchases details, in which i get the purchased date. Now I am able to find the expiry date with this. The method looks like below
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;
}
这篇关于如何在inapp v3 android中获得订阅过期日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!