InApp购买RESTORE_TRANSACTIONS,我不能推测的code OUT [英] InApp Purchase RESTORE_TRANSACTIONS, I am not able to figure the code out

查看:97
本文介绍了InApp购买RESTORE_TRANSACTIONS,我不能推测的code OUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的编码添加在应用程序内购买,它的运作良好,而购买,但给人的错误,当我尝试添加Restore_Transaction code当应用程序被删除并重新安装应用程序关闭,我增加了以下编码

中的onCreate我写

  startService(新意图(mContext,BillingService.class));
        BillingHelper.setCompletedHandler(mTransactionHandler);

        如果(BillingHelper.isBillingSupported()){
            BillingHelper.restoreTransactionInformation(BillingSecurity
                    .generateNonce());
        }
 

,然后我用所谓的处理程序

 公开处理程序mTransactionHandler =新的处理程序(){
        公共无效的handleMessage(android.os.Message味精){
            如果(BillingHelper.latestPurchase.isPurchased()){
                showItem();
            }
        };
    };

    私人无效showItem(){
        购买= Purchased.getPurchaseInfo(getApplicationContext());
        如果(购买== NULL){
            日期D =新的日期();
            Toast.makeText(getApplicationContext(),--- Upgrated ---,
                    Toast.LENGTH_LONG).show();
            购买=新购(getApplicationContext());
            purchased.isPurchased = 1;
            purchased.purchasedDate = d.getTime();
            purchased.save();
            意向意图=新的意图(ActorGenieActivity.this,
                    SplashScreen.class);
            startActivity(意向);
        }
    }
 

解决方案

我找到了答案,我的问题,感谢名单,以anddev

您必须检查采购不为空

 公共静态无效verifyPurchase(字符串签名数据,特征码){
    ArrayList的< VerifiedPurchase>购买= BillingSecurity.verifyPurchase(
            签名数据,签名);
    如果(购买= NULL和放大器;!&安培;!purchases.isEmpty()){
        latestPurchase = purchases.get(0);
        confirmTransaction(新的String [] {latestPurchase.notificationId});
        如果(mCompletedHandler!= NULL){
            mCompletedHandler.sendEmptyMessage(0);
        } 其他 {
            登陆
                    .E(
                            标签,
                            verifyPurchase错误处理程序没有实例化你叫setCompletedHandler()?);
        }
    }
}
 

和在Confirm_Notificationü甲肝检查

 如果(notifyIds [0]!= NULL)
 

I am adding a in app purchase in my coding, it's working well while purchase but gives error and application closes when I try to add Restore_Transaction code when application is removed and installed again, I have added below coding

in onCreate i wrote

startService(new Intent(mContext, BillingService.class));
        BillingHelper.setCompletedHandler(mTransactionHandler);

        if (BillingHelper.isBillingSupported()) {
            BillingHelper.restoreTransactionInformation(BillingSecurity
                    .generateNonce());
        }

and then i called handler using

public Handler mTransactionHandler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (BillingHelper.latestPurchase.isPurchased()) {
                showItem();
            }
        };
    };

    private void showItem() {
        purchased = Purchased.getPurchaseInfo(getApplicationContext());
        if (purchased == null) {
            Date d = new Date();
            Toast.makeText(getApplicationContext(), "--- Upgrated ---",
                    Toast.LENGTH_LONG).show();
            purchased = new Purchased(getApplicationContext());
            purchased.isPurchased = 1;
            purchased.purchasedDate = d.getTime();
            purchased.save();
            Intent intent = new Intent(ActorGenieActivity.this,
                    SplashScreen.class);
            startActivity(intent);
        }
    }

解决方案

I found the answer to my question, thanx to anddev

You have to check for purchases not to be null

public static void verifyPurchase(String signedData, String signature) {
    ArrayList<VerifiedPurchase> purchases = BillingSecurity.verifyPurchase(
            signedData, signature);
    if (purchases != null && !purchases.isEmpty()) {
        latestPurchase = purchases.get(0);
        confirmTransaction(new String[] { latestPurchase.notificationId });
        if (mCompletedHandler != null) {
            mCompletedHandler.sendEmptyMessage(0);
        } else {
            Log
                    .e(
                            TAG,
                            "verifyPurchase error. Handler not instantiated. Have you called setCompletedHandler()?");
        }
    }
}

and in Confirm_Notification u hav to check for

if (notifyIds[0] != null)

这篇关于InApp购买RESTORE_TRANSACTIONS,我不能推测的code OUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆