Hei,
I assume you will use IABv3.
Early in your code, in a billing activity, you will create a
android.vending.billing.helper.IabHelper:
public abstract class PurchaseActivity
extends AppCompatActivity
implements OnIabSetupFinishedListener, OnIabPurchaseFinishedListener,
IabHelper.QueryInventoryFinishedListener
{
private IabHelper billingHelper;
protected String mSku;
@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_purchase);
setResult(RESULT_CANCELED); // set initial value
mSku = "";
// A simple but bad way to retrieve your app public license key
// TODO - make a good improvement
String temp = App.BASE_64_LICENSE_KEY;
// construct the developer payload
/* check we can communicate with the on-device google play app */
billingHelper = new IabHelper( this, temp );
billingHelper.startSetup( this );
}
Much later in your app lifecycle, on completion of a purchase request,
billingHelper will invoke a callback in your code, like:
/**
* Called to notify that an in-app purchase finished. If the purchase was
* successful, then the sku parameter specifies which item was purchased.
* If the purchase failed, the sku and extraData parameters may or may not
* be null, depending on how far the purchase process went.
*
* Security Recommendation: When you receive the purchase response from
* Google Play, make sure to check the returned data signature, the orderId,
* and the DeveloperPayload string in the Purchase object to make sure that
* you are getting the expected values.
*/
@Override
public void onIabPurchaseFinished( IabResult result, Purchase response )
{
if( result.isFailure( ))
{
//Logger.d("Error purchasing: " + result);
dealWithPurchaseFailed( result );
}
else
if( App.SKU.equals( response.getSku( )))
{
dealWithPurchaseSuccess( result, response );
}
else
{
//Logger.d("Unknown sku purchased: " + result);
/* deal locally with successful purchase response for different SKU */
IabResult lResult = new IabResult(
IabHelper.IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Signature verification failed
for sku" );
dealWithPurchaseFailed( lResult );
}
}
And to consume the purchase, later in your app life cycle, you can reuse the
Purchase response parameter as in:
protected void consumePurchase( Purchase response )
{
//Logger.d("revoke license");
/* Consuming a Purchase Item means it has to be bought again.
* For one-off lifetime purchases you don't do this.
* You would do this for many-off consumable purchases, or on detecting
* an illegal use of the Application.
*/
billingHelper.consumeAsync( response, null );
}
You can further google for Mark Blundell tutorial as a starter.
Also wade through google's android.vending.billing.util .IabHelper class.
Hope this helps.
On Friday, December 18, 2015 at 10:02:08 AM UTC, Andre wrote:
>
> Hello,
>
> i want to add some consumable in app items for my game. But the only
> choice is:
>
> - Managed Item
> - Abo
>
> The documentation says:
>
> Before provisioning the consumable in-app product in your application, you
>> must send a consumption request to Google Play and receive a successful
>> response indicating that the consumption was recorded.
>
>
> But where i can do that?
>
> Thank you and best regards
>
> Andre
>
>
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/7a54c474-f62d-4e03-98ac-66861eebc3ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.