【问题标题】:Android billing - item not foundAndroid 计费 - 未找到项目
【发布时间】:2013-04-16 02:37:47
【问题描述】:

我创建了一个订阅产品,当人们尝试购买它时,他们从我的应用点击到应用商店,并收到错误消息“找不到项目”

但这些项目在我的开发者控制台中显示为实时。

我是这样称呼它的:

这是来自此方法的 onActivityResult():

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    sendEmail(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data

结果:

onActivityResult(10001,0,Intent { (has extras) }

和 onIabPurchaseFinished

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() 
{
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) 
    {
        sendEmail(TAG, "Purchase finished: " + result + ", purchase: " + purchase);

似乎从未被处决。

还有

public void onUpgradeAppButtonClicked( ) 
{
    sendEmail(TAG, "Buy button clicked; launching purchase flow for upgrade. SKU: " + SKU_SUBSCRIPTION + " and RC_REQUEST: " + RC_REQUEST );
    //setWaitScreen(true);
    mHelper.launchPurchaseFlow(this, SKU_SUBSCRIPTION, RC_REQUEST, mPurchaseFinishedListener);
}

导致:

点击购买按钮;启动升级购买流程。 SKU:my_sku 和 RC_REQUEST:10001

有人知道为什么会发生错误吗?会不会是某些旧手机会出现这种情况?

另外,如果有人可以在他们的手机上试用它,那会有所帮助,因为我只有一部手机可以测试 :) 这是应用程序的链接: https://play.google.com/store/apps/details?id=com.problemio&hl=en

在主屏幕的最底部按钮上进行结算。

编辑:

我知道有时应用内产品需要时间才能真正在 Android 系统中上线,但它说在我的开发控制台中上线 :)

编辑:

在我的 IABHelper.java 我有这个:

/**
 * Same as calling {@link #launchPurchaseFlow(Activity, String, int, OnIabPurchaseFinishedListener, String)}
 * with null as extraData.
 */
public void launchPurchaseFlow(Activity act, String sku, int requestCode, OnIabPurchaseFinishedListener listener) {
    launchPurchaseFlow(act, sku, requestCode, listener, "");
}

然后是这个:

/**
 * Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
 * which will involve bringing up the Google Play screen. The calling activity will be paused while
 * the user interacts with Google Play, and the result will be delivered via the activity's
 * {@link android.app.Activity#onActivityResult} method, at which point you must call
 * this object's {@link #handleActivityResult} method to continue the purchase flow. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param act The calling activity.
 * @param sku The sku of the item to purchase.
 * @param requestCode A request code (to differentiate from other responses --
 *     as in {@link android.app.Activity#startActivityForResult}).
 * @param listener The listener to notify when the purchase process finishes
 * @param extraData Extra data (developer payload), which will be returned with the purchase data
 *     when the purchase completes. This extra data will be permanently bound to that purchase
 *     and will always be returned when the purchase is queried.
 */
public void launchPurchaseFlow(Activity act, String sku, int requestCode, OnIabPurchaseFinishedListener listener, String extraData) {
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

    try {
        logDebug("Constructing buy intent for " + sku);
        Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, ITEM_TYPE_INAPP, extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));

            result = new IabResult(response, "Unable to buy item");
            if (listener != null) listener.onIabPurchaseFinished(result, null);
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
        mRequestCode = requestCode;
        mPurchaseListener = listener;
        act.startIntentSenderForResult(pendingIntent.getIntentSender(),
                                       requestCode, new Intent(),
                                       Integer.valueOf(0), Integer.valueOf(0),
                                       Integer.valueOf(0));
    }
    catch (SendIntentException e) {
        logError("SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (listener != null) listener.onIabPurchaseFinished(result, null);
    }
    catch (RemoteException e) {
        logError("RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null) listener.onIabPurchaseFinished(result, null);
    }
}

【问题讨论】:

  • 我在 Play 商店下载了您的应用后,我喜欢它。一切运行良好,但在捐赠订阅应用程序时出现未找到项目异常。请在下面查看我的答案。

标签: android android-billing


【解决方案1】:

我没有在应用计费中尝试过订阅,但据我所知,请查看下面的答案。 确保您为产品提供的产品密钥有两件事是正确的。并在项目类型中使用 IabHelper.ITEM_TYPE_SUBS。

  1) static final String SKU_SUBSCRIPTION = "your product id should be here";

  2) mHelper.launchPurchaseFlow(youractivity.this,
                            SKU_SUBSCRIPTION, IabHelper.ITEM_TYPE_SUBS, 
                            RC_REQUEST, mPurchaseFinishedListener, payload); 

请让我确认它对你有用。希望对你有帮助。

检查 IabHelper 方法:

     // The listener registered on launchPurchaseFlow, which we have to call back when
   // the purchase finishes
   OnIabPurchaseFinishedListener mPurchaseListener;

   public void launchPurchaseFlow(Activity act, String sku, int requestCode, OnIabPurchaseFinishedListener listener) {
       launchPurchaseFlow(act, sku, requestCode, listener, "");
   }

   public void launchPurchaseFlow(Activity act, String sku, int requestCode, 
           OnIabPurchaseFinishedListener listener, String extraData) {
       launchPurchaseFlow(act, sku, ITEM_TYPE_INAPP, requestCode, listener, extraData); 
   }

   public void launchSubscriptionPurchaseFlow(Activity act, String sku, int requestCode, 
           OnIabPurchaseFinishedListener listener) {
       launchSubscriptionPurchaseFlow(act, sku, requestCode, listener, "");
   }

   public void launchSubscriptionPurchaseFlow(Activity act, String sku, int requestCode, 
           OnIabPurchaseFinishedListener listener, String extraData) {
       launchPurchaseFlow(act, sku, ITEM_TYPE_SUBS, requestCode, listener, extraData); 
   }

   /**
    * Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
    * which will involve bringing up the Google Play screen. The calling activity will be paused while
    * the user interacts with Google Play, and the result will be delivered via the activity's
    * {@link android.app.Activity#onActivityResult} method, at which point you must call
    * this object's {@link #handleActivityResult} method to continue the purchase flow. This method
    * MUST be called from the UI thread of the Activity.
    *
    * @param act The calling activity.
    * @param sku The sku of the item to purchase.
    * @param itemType indicates if it's a product or a subscription (ITEM_TYPE_INAPP or ITEM_TYPE_SUBS)
    * @param requestCode A request code (to differentiate from other responses --
    *     as in {@link android.app.Activity#startActivityForResult}).
    * @param listener The listener to notify when the purchase process finishes
    * @param extraData Extra data (developer payload), which will be returned with the purchase data
    *     when the purchase completes. This extra data will be permanently bound to that purchase
    *     and will always be returned when the purchase is queried.
    */
   public void launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode,
                       OnIabPurchaseFinishedListener listener, String extraData) {
       checkSetupDone("launchPurchaseFlow");
       flagStartAsync("launchPurchaseFlow");
       IabResult result;

       if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
           IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE, 
                   "Subscriptions are not available.");
           if (listener != null) listener.onIabPurchaseFinished(r, null);
           return;
       }

       try {
           logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
           Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
           int response = getResponseCodeFromBundle(buyIntentBundle);
           if (response != BILLING_RESPONSE_RESULT_OK) {
               logError("Unable to buy item, Error response: " + getResponseDesc(response));

               result = new IabResult(response, "Unable to buy item");
               if (listener != null) listener.onIabPurchaseFinished(result, null);
               return;
           }

           PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
           logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
           mRequestCode = requestCode;
           mPurchaseListener = listener;
           mPurchasingItemType = itemType;
           act.startIntentSenderForResult(pendingIntent.getIntentSender(),
                                          requestCode, new Intent(),
                                          Integer.valueOf(0), Integer.valueOf(0),
                                          Integer.valueOf(0));
       }
       catch (SendIntentException e) {
           logError("SendIntentException while launching purchase flow for sku " + sku);
           e.printStackTrace();

           result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
           if (listener != null) listener.onIabPurchaseFinished(result, null);
       }
       catch (RemoteException e) {
           logError("RemoteException while launching purchase flow for sku " + sku);
           e.printStackTrace();

           result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
           if (listener != null) listener.onIabPurchaseFinished(result, null);
       }
   }

【讨论】:

  • 谢谢。我正在使用的是这个调用: mHelper.launchPurchaseFlow(this, SKU_SUBSCRIPTION, RC_REQUEST, mPurchaseFinishedListener);它没有 ITEM_TYPE_SUBS 或有效负载参数。您使用的是较旧的 api 版本吗?我不确定是否需要有效负载
  • 有趣...你如何构造有效载荷对象?我似乎没有在他们的例子中找到我所拥有的。
  • @Genadinik 正在使用第 3 版的应用内购买。您还可以在 android sdk 中查看默认演示。可能会在 2013 年 2 月之后可用,请查看此链接 android-developers.blogspot.in/2012/12/…
  • 对payload不太了解,但我只使用了一个空字符串 String payload = "";
  • 有趣。我收到此错误:IabHelper 类型中的方法 launchPurchaseFlow(Activity, String, int, IabHelper.OnIabPurchaseFinishedListener, String) 不适用于此方法的参数(SupportActivity, String, String, int, IabHelper.OnIabPurchaseFinishedListener, String): mHelper.launchPurchaseFlow(this, SKU_SUBSCRIPTION, IabHelper.ITEM_TYPE_INAPP, RC_REQUEST, mPurchaseFinishedListener, "");
猜你喜欢
  • 1970-01-01
  • 2012-06-16
  • 2021-01-04
  • 1970-01-01
  • 2022-07-08
  • 2011-07-28
  • 2015-08-06
  • 2022-08-21
  • 2017-05-13
相关资源
最近更新 更多