在应用结算版本2中获取购买历史Android

时间:2014-08-21 16:54:47

标签: android in-app-purchase in-app-billing

如何检查用户是否已购买商品?我的产品是管理的,用户可以购买一次,我希望当用户在购买后点击项目时,即使重新安装应用程序,也应该显示项目... 现在点击btnBuy会出现一个白色的块,上面有消息ERROR和子消息,表明我已经购买了这个项目而没有出现任何其他内容。

其次,如果有办法,我该如何测试呢?

我的代码如下。我在应用程序结算版本2中使用 在我创建的主要活动中我打电话

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

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    if(v.getId()==R.id.btnBUY)
    {

        if(BillingHelper.isBillingSupported()){

            BillingHelper.requestPurchase(mContext, "com.test.buy"); 

            // android.test.purchased or android.test.canceled or android.test.refunded or com.blundell.item.passport
        } else {
            Log.i(TAG,"Can't purchase on this device");
             Toast.makeText(this, "Can't purchase on this device, Billing not Supprted", Toast.LENGTH_SHORT).show();

            hajj.setEnabled(false); // XXX press button before service started will disable when it shouldnt
        }

    }

 public Handler mTransactionHandler = new Handler(){
    public void handleMessage(android.os.Message msg) {
        Log.i(TAG, "Transaction complete");
        Log.i(TAG, "Transaction status: "+BillingHelper.latestPurchase.purchaseState);
        Log.i(TAG, "Item purchased is: "+BillingHelper.latestPurchase.productId);

        if(BillingHelper.latestPurchase.isPurchased()){
            showItem();
        }
    };

};

2 个答案:

答案 0 :(得分:0)

我不熟悉应用内结算,但我建议您使用version 3!可能对您有所帮助的一个功能如下:

  

所有购买均为“管理”(即Google Play会跟踪用户对应用内商品的所有权)。用户不能拥有应用内商品的多个副本;任何时间点都只能拥有一份副本。

答案 1 :(得分:0)

我通过使用应用内结算版本3来解决此问题。它具有更清晰的json响应,然后是v2

这里有0个OK的响应代码 0:OK 和7已经拥有的项目的响应代码 7:项目已经拥有

相关问题