android:Inapp计费:错误响应:7:项目已拥有

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

我正在学习为我的应用实现应用内结算,例如,人们可以在按下捐赠按钮时捐赠 $。

允许用户多次捐赠,即购买为消耗品。

以下代码来自 TrivalDrive 示例和网络上的一些教程:

代码:

IabHelper mHelper;
static final String ITEM_SKU = "android.test.purchased"; 

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_in_app_billing);

    buy10Button = (Button) findViewById(R.id.buy10Button); 
    buy15Button = (Button) findViewById(R.id.buy15Button); 
    buy20Button = (Button) findViewById(R.id.buy20Button);      

    String base64EncodedPublicKey = "keykeykey";

    mHelper = new IabHelper(this, base64EncodedPublicKey);


    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() 
    {
          public void onIabSetupFinished(IabResult result) 
          {
            if (!result.isSuccess()) 
            {
               Log.d(TAG, "In-app Billing setup failed: " + result);
               return;
            } 
            if (mHelper == null) 
            {
                return;
            }          
            Log.d(TAG, "In-app Billing is set up OK");
          }
    });     
}

public void buy10Click(View view) 
{
    mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001,  mPurchaseFinishedListener, "");
}

public void buy15Click(View view) 
{

}

public void buy20Click(View view) 
{

}   

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    if (mHelper == null) return;  
    if (!mHelper.handleActivityResult(requestCode, resultCode, data)) 
    {     
        super.onActivityResult(requestCode, resultCode, data);
    }
}

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() 
{
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) 
    {
        if (mHelper == null) return;
        if (result.isFailure()) 
        {
           // Handle error
               return;
        }      
        else if ((purchase.getSku().equals(ITEM_SKU)))   
        {
           consumeItem();
        }              
    }
};

public void consumeItem() 
{
    mHelper.queryInventoryAsync(mReceivedInventoryListener);
}

IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() 
{
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) 
    {
        if (mHelper == null) return;
        if (result.isFailure()) 
        {
            // Handle failure
        } 
        else 
        {
            mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU), mConsumeFinishedListener);
        }
    }
};

IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() 
{
    public void onConsumeFinished(Purchase purchase, IabResult result) 
    {
        if (mHelper == null) return;
        if (result.isSuccess()) 
        {
            Toast.makeText(InAppBillingActivity.this, "Thank you for your donation!!", Toast.LENGTH_LONG).show();   
        } 
        else 
        {
            // handle error
        }
    }
};

问题:

但我一直收到 E/IabHelper(13392): In-app billing error: Unable to buy item, Error response: 7:Item Already Owned 错误以及 Google 的付款对话框播放只是不弹出。

我研究了很多类似的情况,有的建议等几分钟,然后购买会自动重置,但我等了快一个小时,但还是很糟糕。

我还发现有人建议更改 IabResult public boolean isSuccess() { return mResponse == IabHelper.BILLING_RESPONSE_RESULT_OK; } 也返回 BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED 为 isSuccess = true,但我不知道如何修改...

如何解决问题?谢谢!!

最佳答案

您购买了“android.test.purchased”但没有使用它。但是,如果忘记立即食用,再食用也不是一件容易的事。我们可以等14天。虚假购买将被自动清除。但这是 Not Acceptable 。

我花了很多时间寻找解决方案:

添加此行以获取调试信息。

_iabHelper.enableDebugLogging(true, "TAG");

运行应用程序。在 LogCat 中,你会看到一个 json 字符串,如

{"packageName":"com.example","orderId":"transactionId.android.test.purchased","productId":"android.test.purchased","developerPayload":"123","purchaseTime":0,"purchaseState":0,"purchaseToken":"inapp:com.example:android.test.purchased"}

手动使用(将 THAT_JSON_STRING 替换为您的 json 字符串)

    Purchase purchase;
    try {
        purchase = new Purchase("inapp", THAT_JSON_STRING, "");
        _iabHelper.consumeAsync(purchase, new OnConsumeFinishedListener() {

            @Override
            public void onConsumeFinished(Purchase purchase, IabResult result) {
                Log.d("TAG", "Result: " + result);
            }
        });
    } catch (JSONException e) {
        e.printStackTrace();
    }

_iabHelper 是 mHelper。

关于android:Inapp计费:错误响应:7:项目已拥有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19195864/

相关文章:

java - 如何将此 int 初始化为常量?

android - 按应用程序名称而不是包名称的字母顺序对 ListView 进行排序

java - 检查 Activity 是否在 Service 中启动

android - `SkuType.INAPP`中的 'SkuType.SUBS`和 `In app purchase`有什么区别

android - 如何确认android中的应用内购买?

android - PreferenceFragment 未从应用计费请求中获取 onActivityResult 调用

安卓奥利奥+ : AppWidget click doesn't invoke JobIntentService. onHandleWork()

android - 如何检测 Google Play 购买是从测试帐户还是普通帐户进行的

android - 通过促销代码进行的应用内购买返回空的开发人员有效负载字符串

android - Android 应用内消费品购买支持退款吗? - 应用内计费 API V3