Android in-app billing: custom sku purchase gives “Error - item not found”

后端 未结 4 1497
名媛妹妹
名媛妹妹 2021-01-03 14:35

I\'m trying to test in-app billing using my own sku/product ID \"upgrade_to_premium\". As I have seen recommended here, I am using the Dungeons sample app. I\'ve added a \"n

4条回答
  •  佛祖请我去吃肉
    2021-01-03 14:59

    You should note there are some very misleading errors and dialogs displayed in the demo Dungeons.java:

    --

    If you are getting "Error: This version of the application is not configured for Market billing."

    You must installed the RELEASE apk to your android DEVICE not emulator meaning:

    • Exporting your APK and signing it

    • Deleting any previous installation of your app on your device (even debug / developer versions!)

    • Side loading the APK to your device, installing it, and running it.

    • This also means debugging your released app is probably going to be without your debugger attached. If your debugger is attached, do tell me how!

    If you are getting "Error: Item not found", there's a decent chance there is nothing wrong.

    Dungeons.java actually has a bug in it. Let me explain:

    /**
     * Called when a button is pressed.
     */
    @Override
    public void onClick(View v) {
        if (v == mBuyButton) {
            if (Consts.DEBUG) {
                Log.d(TAG, "buying: " + mItemName + " sku: " + mSku);
            }
    
            if (mManagedType != Managed.SUBSCRIPTION &&
                     // ** The following line is bug when returns !true which is false, and then makes the if statement false
                    !mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_INAPP, mPayloadContents)) { 
                showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
    
                // ** Which then ends up running this else if, meaning it will try to purchase a subscription
            } else if (!mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_SUBSCRIPTION, mPayloadContents)) {
                // Note: mManagedType == Managed.SUBSCRIPTION
                showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
            }
        } else if (v == mEditPayloadButton) {
            showPayloadEditDialog();
        } else if (v == mEditSubscriptionsButton) {
            editSubscriptions();
        }
    }
    

    Rather it should be written like this:

    /**
     * Called when a button is pressed.
     */
    @Override
    public void onClick(View v) {
        if (v == mBuyButton) {
            if (Consts.DEBUG) {
                Log.d(TAG, "buying: " + mItemName + " sku: " + mSku);
            }
    
            // We need this statement to evaluate to true on a Non-Subscription such as a Managed or Unmanaged Purchase
            if (mManagedType != Managed.SUBSCRIPTION) { 
    
                    // If the following errors out, show an error dialog.  However, it should not make the previous if statement false
                    if( !mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_INAPP, mPayloadContents)) { 
                        showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
                    }
    
            } 
    
             // This if statement gets run accidentally without the bug fix, thus trying to buy your "SKU" as a "subscription", which is totally wrong!
            else if (!mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_SUBSCRIPTION, mPayloadContents)) { 
                // Note: mManagedType == Managed.SUBSCRIPTION
                showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
            }
        } else if (v == mEditPayloadButton) {
            showPayloadEditDialog();
        } else if (v == mEditSubscriptionsButton) {
            editSubscriptions();
        }
    }
    

提交回复
热议问题