Java tutorial
////////////////////////////////////////////////////////////////////////////////////// // // Copyright 2012 Freshplanet (http://freshplanet.com | opensource@freshplanet.com) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ////////////////////////////////////////////////////////////////////////////////////// package com.freshplanet.inapppurchase; import org.json.JSONException; import android.util.Log; import com.adobe.fre.FREContext; import com.adobe.fre.FREFunction; import com.adobe.fre.FREInvalidObjectException; import com.adobe.fre.FREObject; import com.adobe.fre.FRETypeMismatchException; import com.adobe.fre.FREWrongThreadException; public class RemovePurchaseFromQueuePurchase implements FREFunction { private static String TAG = "RemovePurchase"; // Called when consumption is complete IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() { public void onConsumeFinished(Purchase purchase, IabResult result) { Log.d(TAG, "Consumption finished. Purchase: " + purchase + ", result: " + result); if (result.isSuccess()) { Log.d(TAG, "Successfully consume " + purchase); } else { Log.e(TAG, "Error while consuming: " + result); } Log.d(TAG, "End consumption flow."); } }; @Override public FREObject call(FREContext arg0, FREObject[] arg1) { Log.d(TAG, "starting confirming purchases"); String purchaseStr = null; try { purchaseStr = arg1[0].getAsString(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (FRETypeMismatchException e) { e.printStackTrace(); } catch (FREInvalidObjectException e) { e.printStackTrace(); } catch (FREWrongThreadException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } Log.d(TAG, "purchase id : " + purchaseStr); String token = null; try { token = arg1[1].getAsString(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (FRETypeMismatchException e) { e.printStackTrace(); } catch (FREInvalidObjectException e) { e.printStackTrace(); } catch (FREWrongThreadException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } IabHelper mHIabHelper = ExtensionContext.mHelper; if (mHIabHelper == null) { Log.e(TAG, "iabHelper is not init"); return null; } Purchase p = new Purchase(purchaseStr, token); mHIabHelper.consumeAsync(p, mConsumeFinishedListener); return null; } }