Android的 - 测试与真正的产品ID计费购给出错误:没有找到 [英] Android - testing billing purchase with real item id gives error: Item Not Found

查看:145
本文介绍了Android的 - 测试与真正的产品ID计费购给出错误:没有找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里我与该项目ID的测试设备上进行测试的情况:android.test.purchased
而事情的来龙去脉。然后,一旦我改变了字符串实物ID,我开始没有找到错误,当我pressed购买按钮。

另外,购买产品的订阅,而不是1次购买。这是否有所作为?

我不知道其中code的一部分,可能有故障,或者是可能缺少所以这里是这个类:

 公共类SubscribeIntroActivity扩展BaseActivity
{
    IabHelper mHelper;    //用户是否具有premium升级?
    布尔isSubscriber = FALSE;    //(任意)请求code购买流程
    静态最终诠释RC_REQUEST = 105;    //订阅SKU
    静态最后弦乐SUBSCRIBE_SKU =11;    //订阅SKU
    静态最后弦乐TAG =计费;    / **当第一次创建活动调用。 * /
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.subscribe_intro);        字符串base64En codedPublicKey =my_real_key;        //创建助手,传递我们的背景和公钥来验证签名与
        mHelper =新IabHelper(这一点,base64En codedPublicKey);
        mHelper.enableDebugLogging(真);        mHelper.startSetup(新IabHelper.OnIabSetupFinishedListener(){
            公共无效onIabSetupFinished(IabResult结果)
            {
                如果(!result.isSuccess())
                {
                    //呵呵不一,有一个问题。
                    //抱怨(问题设置应用内结算:+结果);
                    返回;
                }                //万岁,IAB是完全成立。现在,让我们的东西的清单,我们自己的。
                mHelper.queryInventoryAsync(mGotInventoryListener);
            }
        });        //监听器,当我们完成查询,我们拥有的项目,被称为
        IabHelper.QueryInventoryFinishedListener mGotInventoryListener =新IabHelper.QueryInventoryFinishedListener(){
            公共无效onQueryInventoryFinished(IabResult结果,库存盘点){                如果(result.isFailure())
                {
                    //抱怨(无法查询盘点:+结果);
                    返回;
                }                Log.d(TAG,查询库存是成功的。);                //我们是否有premium升级?
                isSubscriber = inventory.hasPurchase(SUBSCRIBE_SKU);
                Log.d(TAG,用户是+(isSubscriber订户:NOT认购人」));                //检查气体输送 - 如果我们自己的气,我们应该立即注满油箱
                如果(inventory.hasPurchase(SUBSCRIBE_SKU))
                {
                    Log.d(TAG,已认购);
                    返回;
                }
                //的updateUI();
                // TODO:告诉用户以他正在SUBSCIBED并把他们的问题                // setWaitScreen(假);
                Log.d(TAG,初始库存查询完毕;支持主界面。);
            }
        };        按钮订阅=(按钮)findViewById(R.id.subscribe);
        subscribe.setOnClickListener(新Button.OnClickListener()
        {
           公共无效的onClick(视图v)
           {
               //首先检查用户是否已经是订户。
              mHelper.launchPurchaseFlow(SubscribeIntroActivity.this,SUBSCRIBE_SKU,RC_REQUEST,mPurchaseFinishedListener);
               //给我的评论是就某一问题提交的电子邮件。
              // sendEmail(我的问题 - >添加问题,有人点击了插件的问题从我的问题用户名:+ USER_ID);              //意图myIntent =新意图(Motivati​​onActivity.this,WePromoteActivity.class);
              //Motivati​​onActivity.this.startActivity(myIntent);
           }
        });
// mHelper.startSetup(新IabHelper.OnIabSetupFinishedListener(){
//公共无效onIabSetupFinished(IabResult结果)
// {
//如果(!result.isSuccess())
// {
// //呵呵不一,有一个问题。
//
// Log.d(应用程式内计费,问题设置在应用内结算:+结果);
//}
//
// //万岁,IAB是完全成立!
//
//
// //第一个参数是产品的细节是否应该被检索
// //列表参数包括对于您要查询的产品的一个或多个产品标识(也称为SKU)的。
// //在QueryInventoryFinishedListener参数指定一个监听器
// //当查询操作完成通知
// //并处理查询响应。
//// mHelper.queryInventoryAsync(假,新的ArrayList()。新增(1),
//// mQueryFinishedListener);
//
// //mHelper.queryInventoryAsync(mGotInventoryListener);
//
//
//// mHelper.launchPurchaseFlow(SubscribeIntroActivity.this,11,105,mPurchaseFinishedListener,);
//}
//});
    }    IabHelper.QueryInventoryFinishedListener
    mQueryFinishedListener =新IabHelper.QueryInventoryFinishedListener()
    {
        公共无效onQueryInventoryFinished(IabResult结果,库存盘点)
        {
           如果(result.isFailure()){
              //处理错误
              返回;
            }            字符串applePrice =
               inventory.getSkuDetails(1)用getPrice();
            字符串bananaPrice =
               inventory.getSkuDetails(SUBSCRIBE_SKU).getPrice();
        }
        //更新UI
    };    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
    =新IabHelper.OnIabPurchaseFinishedListener(){
    公共无效onIabPurchaseFinished(IabResult结果,购购)
    {
       如果(result.isFailure())
       {
          Log.d(ERROR,错误的采购:+结果);
          返回;
       }
       否则如果(purchase.getSku()。等于(1))
       {
          //消耗气体和更新UI
       }       否则,如果(purchase.getSku()。等于(SUBSCRIBE_SKU))
       {
          //给用户以premium内容访问和更新用户界面
           Log.d(TAG,购买:+结果);       }
    }
 };     IabHelper.QueryInventoryFinishedListener mGotInventoryListener
     =新IabHelper.QueryInventoryFinishedListener(){
     公共无效onQueryInventoryFinished(IabResult结果,
        库存存货){        如果(result.isFailure()){
          //这里处理错误
        }
        其他
        {
          //用户是否具有premium升级?
          isSubscriber = inventory.hasPurchase(SUBSCRIBE_SKU);
          //更新相应的UI
        }
     }
    };
    @覆盖
    保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
        Log.d(TAG的onActivityResult(+请求code +,+结果code +,+数据);        //对活动的结果传递给帮手处理
        如果(!mHelper.handleActivityResult(要求code,结果code,数据)){
            //没有处理,因此处理它自己(在这里就是你会
            //执行不相关的活动结果的任何处理应用程序内
            //结算...
            super.onActivityResult(要求code,结果code,数据);
        }
        其他{
            Log.d(TAG的onActivityResult由IABUtil处理。);
        }
    }    @覆盖
    公共无效的onDestroy()
    {
       super.onDestroy();       如果(mHelper!= NULL)mHelper.dispose();
       mHelper = NULL;
    }
}


解决方案

我不认为新的应用内结算3版目前支持订阅。我可能是错的,但我还没有看到样品code或文档订阅任何提及,所以这可能是为什么你收到找不到项目的错误。

在一般情况下,测试购买真材实料,你需要一个应用程式版本上传到开发者控制台(但你并不需要发布它),你必须使用相同的(签署)版本来测试。它也需要谷歌播放一些时间来处理/传播新添加的项目......所以有时你很不幸只需要等待。请查看 developer.android.com/training/in-app -billing /测试IAB-app.html 如果您还没有。

I have a situation where I tested on a test device with the item id: android.test.purchased And things worked. Then once I changed that string with the real item id, I started getting Item Not Found error when I pressed the buy button.

Also the buy item is a subscription and not a 1-time purchase. Does that make a difference?

I was not sure which part of the code may be at fault, or what may be missing so here is the class for this:

public class SubscribeIntroActivity extends BaseActivity
{
    IabHelper mHelper;

    // Does the user have the premium upgrade?
    boolean isSubscriber = false;   

    // (arbitrary) request code for the purchase flow
    static final int RC_REQUEST = 105;

    // Subscribe SKU
    static final String SUBSCRIBE_SKU = "11";

    // Subscribe SKU
    static final String TAG = "BILLING";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.subscribe_intro);



        String base64EncodedPublicKey = "my_real_key";

        // Create the helper, passing it our context and the public key to verify signatures with
        mHelper = new IabHelper(this, base64EncodedPublicKey);
        mHelper.enableDebugLogging(true);

        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) 
            {
                if (!result.isSuccess()) 
                {
                    // Oh noes, there was a problem.
                    //complain("Problem setting up in-app billing: " + result);
                    return;
                }

                // Hooray, IAB is fully set up. Now, let's get an inventory of stuff we own.
                mHelper.queryInventoryAsync(mGotInventoryListener);
            }
        });        

        // Listener that's called when we finish querying the items we own
        IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
            public void onQueryInventoryFinished(IabResult result, Inventory inventory) {

                if (result.isFailure()) 
                {
                    //complain("Failed to query inventory: " + result);
                    return;
                }

                Log.d(TAG, "Query inventory was successful.");

                // Do we have the premium upgrade?
                isSubscriber = inventory.hasPurchase(SUBSCRIBE_SKU);
                Log.d(TAG, "User is " + (isSubscriber ? "SUBSCRIBER" : "NOT SUBSCRIBER"));

                // Check for gas delivery -- if we own gas, we should fill up the tank immediately
                if (inventory.hasPurchase( SUBSCRIBE_SKU )) 
                {
                    Log.d(TAG, "HAS SUBSCRIPTION");
                    return;
                }


                //updateUi();
                // TODO: TELL USER HE IS SUBSCIBED AND TAKE THEM TO THE QUESTION



                //setWaitScreen(false);
                Log.d(TAG, "Initial inventory query finished; enabling main UI.");
            }
        };



        Button subscribe = (Button)findViewById(R.id.subscribe);
        subscribe.setOnClickListener(new Button.OnClickListener() 
        {  
           public void onClick(View v) 
           {              
               // FIRST CHECK IF THE USER IS ALREADY A SUBSCRIBER.
              mHelper.launchPurchaseFlow(SubscribeIntroActivity.this, SUBSCRIBE_SKU, RC_REQUEST, mPurchaseFinishedListener);


               // Send me an email that a comment was submitted on a question. 
              //sendEmail("My Questions -> Add Question", "Someone clicked on add-question from my questions.  User id: " + user_id  );   

              //Intent myIntent = new Intent(MotivationActivity.this, WePromoteActivity.class);
              //MotivationActivity.this.startActivity(myIntent);              
           }
        });         






//        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
//             public void onIabSetupFinished(IabResult result) 
//             {
//                if (!result.isSuccess()) 
//                {
//                   // Oh noes, there was a problem.
//                    
//                   Log.d("INAPP BILLING", "Problem setting up In-app Billing: " + result);
//                }            
//                      
//                // Hooray, IAB is fully set up!  
//                
//                
//                // First arg is whether product details should be retrieved
//                // The List argument consists of one or more product IDs (also called SKUs) for the products that you want to query.
//                // the QueryInventoryFinishedListener argument specifies a listener is 
//                // notified when the query operation has completed 
//                // and handles the query response.
////                  mHelper.queryInventoryAsync(false, new ArrayList ( ).add("1"), 
////                          mQueryFinishedListener);
//                
//                //mHelper.queryInventoryAsync(mGotInventoryListener);
//                
//                
////                  mHelper.launchPurchaseFlow(SubscribeIntroActivity.this, "11" , 105, mPurchaseFinishedListener, "" );             
//             }
//          });        
    }

    IabHelper.QueryInventoryFinishedListener 
    mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() 
    {
        public void onQueryInventoryFinished(IabResult result, Inventory inventory)   
        {
           if (result.isFailure()) {
              // handle error
              return;
            }

            String applePrice =
               inventory.getSkuDetails("1").getPrice();
            String bananaPrice =
               inventory.getSkuDetails(SUBSCRIBE_SKU).getPrice();
        }
        // update the UI 
    };

    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener 
    = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) 
    {
       if (result.isFailure()) 
       {
          Log.d("ERROR", "Error purchasing: " + result);
          return;
       }      
       else if (purchase.getSku().equals("1")) 
       {
          // consume the gas and update the UI
       }

       else if (purchase.getSku().equals(SUBSCRIBE_SKU)) 
       {
          // give user access to premium content and update the UI
           Log.d(TAG, "PURCHASED: " + result);

       }
    }
 };    

     IabHelper.QueryInventoryFinishedListener mGotInventoryListener 
     = new IabHelper.QueryInventoryFinishedListener() {
     public void onQueryInventoryFinished(IabResult result,
        Inventory inventory) {

        if (result.isFailure()) {
          // handle error here
        }
        else 
        {
          // does the user have the premium upgrade?
          isSubscriber = inventory.hasPurchase(SUBSCRIBE_SKU);        
          // update UI accordingly
        }
     }
    }; 


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);

        // Pass on the activity result to the helper for handling
        if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
            // not handled, so handle it ourselves (here's where you'd
            // perform any handling of activity results not related to in-app
            // billing...
            super.onActivityResult(requestCode, resultCode, data);
        }
        else {
            Log.d(TAG, "onActivityResult handled by IABUtil.");
        }
    }

    @Override
    public void onDestroy() 
    {
       super.onDestroy();   

       if (mHelper != null) mHelper.dispose();
       mHelper = null;
    }
}

解决方案

I don't think the new in-app billing version 3 currently supports subscriptions. I could be wrong, but I haven't seen any mention of subscriptions in the sample code or documentation, so that could be why you're receiving the the "Item not found" error.

In general, to test purchasing a real item, you need to upload a version of your app to the developer console (but you don't need to publish it), and you have to be using the same (signed) version to test with. It also takes Google Play some time to process/propagate newly added items...so sometimes you unfortunately just need to wait. Check out developer.android.com/training/in-app-billing/test-iab-app.html if you haven't already.

这篇关于Android的 - 测试与真正的产品ID计费购给出错误:没有找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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