1

Android documentation says that this method is deprecated, but I do not see what else I can use instead.

Basically, I am trying to do something like this:

if (mBillingService.requestPurchase(issueProductIdPsych, Consts.ITEM_TYPE_INAPP ,  null)) 
{
   // Check what happened? Did the person finish the purchase? did they cance?
   if(mBillingService.checkBillingSupported(Consts.ITEM_TYPE_INAPP))
   {

   }                              

    //BillingHelper.requestPurchase(mContext, "android.test.purchased");
    // android.test.purchased or android.test.canceled or android.test.refunded
}

What is the correct way to accomplish checking what the end of the purchase request was?

I have a buy button like this:

        buy.setOnClickListener(new Button.OnClickListener() 
        {  
           public void onClick(View v) 
           {

But I am not really clear what needs to be done next.

Thanks!

Genadinik
  • 18,153
  • 63
  • 185
  • 284

1 Answers1

1

Wish it was simpler to just replace the code with what you need, but apparently google describes an alternative option. You'd have to implement the MarketBillingService interface. So it's just a little tweak in design. Fortunately, they show you how to accomplish this.

http://developer.android.com/guide/google/play/billing/billing_integrate.html

Go down to the topic where it says "Creating a Local Service". The subcategories are:

  • Binding to the MarketBillingService
  • Sending billing requests to the MarketBillingService
  • Verifying that in-app billing is supported (CHECK_BILLING_SUPPPORTED)
  • Making a purchase request (REQUEST_PURCHASE)

To paraphrase what was written, I'll just describe it here:

In the category: "Verifying that in-app billing is supported (CHECK_BILLING_SUPPPORTED)" They request that you use the sendBillingRequest(). This allows you to send five different types of billing requests:

  • CHECK_BILLING_SUPPORTED—verifies that the Google Play application supports in-app billing and the version of the In-app Billing API available.
  • REQUEST_PURCHASE—sends a purchase request for an in-app item.
  • GET_PURCHASE_INFORMATION—retrieves transaction information for a purchase or refund.
  • CONFIRM_NOTIFICATIONS—acknowledges that you received the transaction information for a purchase or refund.
  • RESTORE_TRANSACTIONS—retrieves a user's transaction history for managed purchases.

Says you have to create a bundle before you perform the request.

Here is an example of how to perform an acknowledgement:

Bundle request = makeRequestBundle("CONFIRM_NOTIFICATIONS");
request.putStringArray(NOTIFY_IDS, mNotifyIds);
Bundle response = mService.sendBillingRequest(request);

Once you retrieve the response, check the contents within the Bundle, there will be three key items: RESPONSE_CODE, PURCHASE_INTENT, and REQUEST_ID. The RESPONSE_CODE key provides you with the status of the request and the REQUEST_ID key provides you with a unique request identifier for the request. The PURCHASE_INTENT key provides you with a PendingIntent, which you can use to launch the checkout UI.

sksallaj
  • 3,872
  • 3
  • 37
  • 58
  • yeah I read that documentation, but not sure exactly what to do. Have you done this with creating the bundle? In their dungeons example they do it like I have the code. When and how do I sendBillingRequest ? Thanks! – Genadinik Jul 24 '12 at 23:06
  • Yes, the bundle is used as a request and response, it makes the code a lot simpler to use and control with. The response will tell you whether or not the request was successful. – sksallaj Jul 24 '12 at 23:10
  • sorry, had to step away from the computer. I am still not really sure how this code would work with the setup that I have. What are the steps that need to be done after the buy button is clicked? – Genadinik Jul 25 '12 at 00:42
  • I was trying to switch to the design you suggested, but I got a bit stuck..any chance you would know the answer to my question here: http://stackoverflow.com/questions/11651557/android-billing-should-i-implement-the-serviceconnection-or-the-imarketbilling – Genadinik Jul 25 '12 at 14:35
  • After you set up everything, in the buy button, you look at the "Binding to the MarketBillingService". The document is telling you to create a local service in your manifestfile, bind it to the MarketBillingService, check if connected, send a billing request, receive one, acknowledge it, and handling a pendingIntent upon the acknowledgement. There is also a recommended way to test since you cannot test it out on an emulator: http://developer.android.com/guide/google/play/billing/billing_testing.html – sksallaj Jul 25 '12 at 14:53
  • yes I understand those steps at a high level reasonably well now, but the problem is that when I try to build it, there are a number of approaches I see taken, and I keep getting confused by what the precise code need to be. is there any way you can post some more code of how you have it? – Genadinik Jul 25 '12 at 15:01
  • You put the Bundles request and response when you click the button. The mService part of the MarketBillingService interface, which should be part of your package if you binded everything properly. You set it when you use add the onServiceConnected, which gets called implicitly by the Android system upon connection to the MarketBillingService (after your program finishes execting the Bundle request line). The mService gets set during runtime. I'm assuming this is an async callback, which is what you're having problems understanding. – sksallaj Jul 26 '12 at 13:44
  • The point is, you don't have to recreate a service (reinventing the wheel) when the service is already provided for you. It includes: mService and onServiceConnected (which you are filling the definition for). The real problem is the testing part since your emulator won't be connected to the market, and testing for async callbacks. So you have to test AFTER you finish coding everything, which can be a pain. – sksallaj Jul 26 '12 at 13:47