OnIabPurchaseFinishedListener not called in helper class - java

trying to use in app billing in Android at the moment.
Everything works fine and I can purchase items and query existing ones but my OnIabPurchaseFinishedListener listener is not being called during a successful purchase. It is called when there is an issue but not on a completed purchase.
I have my main activity, with fragments and a navigation drawer. (fragments are not touched here. I have a helper class that all the billing happens in.
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, MyBilling.Update {\
MyBilling bill;
OnCreate(){
bill = new MyBilling(this, this);
bill.onCreate();
}
private void RemoveAdsClick()
{
bill.purchaseRemoveAds();
}
public void NewPurchaseUpdate(){
tinydb.putBoolean("Premium", true);
nav_Menu.findItem(R.id.remove_ad_button).setVisible(false);
displaySelectedScreen(R.id.distance_check); // Reload screen
}
}
public class MyBilling extends Activity {
////Interface
public interface Update {
void NewPurchaseUpdate();
}
// Debug tag, for logging
static final String TAG = "XXXXXX";
static final String SKU_REMOVE_ADS = "remove_ads";
// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 10111;
// Activity
Activity activity;
// The helper object
IabHelper mHelper;
String base64EncodedPublicKey = "xxxxxxxx";
String payload = "xxxxx";
public boolean isAdsDisabled = false;
public boolean AdCheck = false;
////Instance of interface
Update myActivity;
public MyBilling(Activity launcher,Update activity) {
this.activity = launcher;
myActivity = activity;
}
// User clicked the "Remove Ads" button.
public void purchaseRemoveAds() {
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
mHelper.launchPurchaseFlow(activity, SKU_REMOVE_ADS,
RC_REQUEST, mPurchaseFinishedListener, payload);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
if (mHelper == null) return;
// 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.");
}
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener()
{
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, "Purchase finished: " + result + ", purchase: "
+ purchase);
// if we were disposed of in the meantime, quit.
if (mHelper == null)
return;
if (result.isFailure()) {
complain("Error purchasing: " + result);
return;
}
if (!verifyDeveloperPayload(purchase)) {
complain("Error purchasing. Authenticity verification failed.");
return;
}
Log.d(TAG, "Purchase successful.");
if (purchase.getSku().equals(SKU_REMOVE_ADS)) {
// bought the premium upgrade!
myActivity.NewPurchaseUpdate();
Log.d(TAG, "New Purchase Update Method was called");
}
}
};
}
some googling showed that it could be an issue with onActivityResult not being in the helper class. So I made billing class extend activity and then added onActivityResult and #Override but this also is not called with any breakpoints.
As mentioned above, OnIabPurchaseFinishedListener is called for a failed purchase (already own item) but not for a successful one.
Any help here would be great, I have tried to keep the code as light as possible to help with reading. If I'm missing anything please let me know.

I have fixed this issue by ditching my helper class for now and moving the billing tasks into the main activity.

Related

How to pass data from Java Activity to react native?

I am unable to pass data from java activity to react native.
I am processing a card payment, and when the payment is done, the response is stored in a variable called message. I need to pass this message to my react native code.
// Java module, the data I want to pass is in "message"
public class HelloWorldModule extends ReactContextBaseJavaModule implements ActivityEventListener{
Activity activity;
ReactApplicationContext reactContext;
public HelloWorldModule(ReactApplicationContext reactContext,Activity activity) {
super(reactContext); //required by React Native
this.reactContext= reactContext;
this.activity= activity;
reactContext.addActivityEventListener(this); //Register this native module as Activity result listener
}
#Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
// ReactApplicationContext reactContext = this.getReactNativeHost().getReactInstanceManager().getCurrentReactApplicationContext();
// reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit();
// reactContext
// .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
// .emit('message', message);
/*
* We advise you to do a further verification of transaction's details on your server to be
* sure everything checks out before providing service or goods.
*/
if (requestCode == RaveConstants.RAVE_REQUEST_CODE && data != null) {
String message = data.getStringExtra("response");
// Log.e("RAVE",message);
if (resultCode == RavePayActivity.RESULT_SUCCESS) {
Toast.makeText(activity, "SUCCESS " + message, Toast.LENGTH_SHORT).show();
}
else if (resultCode == RavePayActivity.RESULT_ERROR) {
Toast.makeText(activity, "ERROR " + message, Toast.LENGTH_SHORT).show();
}
else if (resultCode == RavePayActivity.RESULT_CANCELLED) {
Toast.makeText(activity, "CANCELLED " + message, Toast.LENGTH_SHORT).show();
}
}
// else {
// super.onActivityResult(activity, requestCode, resultCode, data);
// }
}
// #Override
// public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
// Toast.makeText( activity , "hello", Toast.LENGTH_SHORT).show();
// }
#Override
public void onNewIntent(Intent intent) {
}
#Override
//getName is required to define the name of the module represented in JavaScript
public String getName() {
return "HelloWorld";
}
#ReactMethod
public void sayHi(Callback errorCallback, Callback successCallback) {
try{
int amount = 30;//call.argument("amount");
String narration = "Payment for soup";//call.argument("nara");
String countryCode = "NG"; //call.argument("countryCode");
String currency = "NGN"; //call.argument("currency");
String amountText = "50";//call.argument("amountText");
String email = "*****#yahoo.com";//call.argument("email");
String name = "Ubanna Danny";//call.argument("name");
String paymentId = "a98sjkhdjdu";//call.argument("paymentId");
String key ="FLWPUBK-****-X";
String encryptionKey = "****";
new RavePayManager(activity).setAmount(Double.parseDouble(String.valueOf(amount)))
.setCountry(countryCode)
.setCurrency(currency)
.setEmail(email)
.setfName(name)
.setlName("")
.setNarration(narration)
.setPublicKey(key)
.setEncryptionKey(encryptionKey)
.setTxRef(paymentId)
.acceptMpesaPayments(false)
.acceptAccountPayments(true)
.acceptCardPayments(true)
.acceptGHMobileMoneyPayments(false)
.onStagingEnv(false)
.allowSaveCardFeature(true)
.initialize();
} catch (IllegalViewOperationException e) {
errorCallback.invoke(e.getMessage());
}
}
}
// React native code
// async function to call the Java native method
async sayHiFromJava() {
HelloWorld.sayHi( (err) => {console.log(err)}, (msg) => {console.log(msg)} );
}
Please help.
use device emitter to send data from native to react native
in on activity result add following code
ReactContext context = this.getReactNativeHost().getReactInstanceManager().getCurrentReactContext();
context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit();
context
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit('message', message);
in react native add Dives emiter listener
import {DeviceEventEmitter} from 'react-native';
EmitterModule.addListener('message', (message) => {
console.log(message);
};

Android in-app billing Purchase dialog not showing after startPurchaseFlow() is called

Hello guys and good saturday everyone,
For the first time i'm implementing an in-app billing service in my app, the aim is to make a "Buy pro and remove ads" button inside app menu, quite simple actually.
Following some guides i made a BillingManager.java:
public class BillingManager implements PurchasesUpdatedListener {
private static final String TAG = "BillingManager";
private final BillingClient mBillingClient;
private final Activity mActivity;
public BillingManager(Activity activity) {
mActivity = activity;
mBillingClient = BillingClient.newBuilder(mActivity).setListener(this).build();
mBillingClient.startConnection(new BillingClientStateListener() {
#Override
public void onBillingSetupFinished(#BillingClient.BillingResponse int billingResponse) {
if (billingResponse == BillingClient.BillingResponse.OK) {
Log.i(TAG, "onBillingSetupFinished() response: " + billingResponse);
} else {
Log.w(TAG, "onBillingSetupFinished() error code: " + billingResponse);
}
}
#Override
public void onBillingServiceDisconnected() {
Log.w(TAG, "onBillingServiceDisconnected()");
}
});
}
#Override
public void onPurchasesUpdated(int responseCode, List<Purchase> purchases) {
Log.i(TAG, "onPurchasesUpdated() response: " + responseCode);
}
public void startPurchaseFlow(String skuId, String billingType) {
BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
.setType(billingType).setSku(skuId).build();
mBillingClient.launchBillingFlow(mActivity, billingFlowParams);
Log.i(TAG, "Received command");
}}
and then i'm calling it inside MainActivity in the menu:
if (id == R.id.action_pro) {
BillingManager mbilling = new BillingManager(MainActivity.this);
mbilling.startPurchaseFlow("mysku", BillingClient.SkuType.INAPP);
return true;
}
But when i press the button corresponding to "action_pro" Nothing happens.
All the logs shows everything is fine, onBillingSetupFinished() response is always 0 and onPurchaseUpdated() response is alwasy -1.
There aren't any crashes or error, just nothing happens...
What can i do?
Any answer is as always highly appreciated!
Edit: i put a logger for debug and i se that if put int response = mBillingClient.launchBillingFlow(mActivity, builder.build());
Log.i(TAG, "Response code: "+ response);
i get the error: I/BillingManager: Response code: -1
So actually mBillingClient.launchBillingFlow(mActivity, builder.build()); throws -1 as result... Any ideas?

Cancel SpeechRecognition if nothing captured

I am trying to develop and app that listens and speaks back to the user. I am trying to make it as handsfree as possible.
My issue is that if the user does not respond in time, the SpeechRecognition will timeout, and the user will need to press the button to start listening again.
*Is there a way for me to do a work around where if nothing is heard by the application, it can prompt to try again and restart the listener?
CODE:
//Function i call when a user input is required.
private void promptSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.speech_not_supported),
Toast.LENGTH_SHORT).show();
}
}
/**
* Receiving speech input
* */
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println("REQUEST CODE: " + requestCode);
switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
System.out.println("resultCode: " + resultCode);
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
txtSpeechInput.setText(result.get(0));
input = result.get(0).toLowerCase();
}
break;
}
}
}
I also have code that will read text to the user, and then prompt for voice input after its finished.
Please let me know if i can provide more details or code. Thanks much!
To make google speech handsfree without clicking the "mic button", you have to make your own class for the recognizer, i wrote the code in xamarin-android, so it's pretty similar on java :
Public class CustomRecognizer : Java.Lang.Object, IRecognitionListener, TextToSpeech.IOnInitListener
{
private SpeechRecognizer _speech;
private Intent _speechIntent;
public string Words;
public CustomRecognizer(Context _context)
{
this._context = _context;
Words = "";
_speech = SpeechRecognizer.CreateSpeechRecognizer(this._context);
_speech.SetRecognitionListener(this);
_speechIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
_speechIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm);
_speechIntent.PutExtra(RecognizerIntent.ActionRecognizeSpeech, RecognizerIntent.ExtraPreferOffline);
_speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1000);
_speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1000);
_speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 1500);
}
void startover()
{
_speech.Destroy();
_speech = SpeechRecognizer.CreateSpeechRecognizer(this._context);
_speech.SetRecognitionListener(this);
_speechIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
_speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1000);
_speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1000);
_speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 1500);
StartListening();
}
public void StartListening()
{
_speech.StartListening(_speechIntent);
}
public void StopListening()
{
_speech.StopListening();
}
public void OnBeginningOfSpeech()
{
}
public void OnBufferReceived(byte[] buffer)
{
}
public void OnEndOfSpeech()
{
}
public void OnError([GeneratedEnum] SpeechRecognizerError error)
{
Words = error.ToString();
startover();
}
When the recognizer got timeout, it will call OnError Event
. On my code, i put startover() to restart the recording.

Android In App Billing: Start purchase flow when button is pressed

I have implemented In-App Billing in my Activity following the google GitHub example
this is my code:
public class Premium extends Activity implements IabBroadcastReceiver.IabBroadcastListener {
Button premium;
//toast
Context context = getBaseContext();
int duration = Toast.LENGTH_SHORT;
//debug tag
static final String TAG = "CHORDS";
//does the user have premium?
boolean mIsPremium = false;
//SKUs
static final String SKU_PREMIUM = "chords_premium";
// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 10001;
// The helper object
IabHelper mHelper;
// Provides purchase notification while this app is running
IabBroadcastReceiver mBroadcastReceiver;
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.premium_layout);
premium = (Button) findViewById(R.id.premium);
String base64EncodedPublicKey = "Key"
// Create the helper, passing it our context and the public key to verify signatures with
Log.d(TAG, "Creating IAB helper.");
mHelper = new IabHelper(this, base64EncodedPublicKey);
// Start setup. This is asynchronous and the specified listener
// will be called once setup completes.
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if (!result.isSuccess()) {
// Oh noes, there was a problem.
Log.d(TAG, "Problem setting up in-app billing: " + result);
return;
}
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
mBroadcastReceiver = new IabBroadcastReceiver(Premium.this);
IntentFilter broadcastFilter = new IntentFilter(IabBroadcastReceiver.ACTION);
registerReceiver(mBroadcastReceiver, broadcastFilter);
Log.d(TAG, "Setup successful. Querying inventory.");
try {
mHelper.queryInventoryAsync(mGotInventoryListener);
} catch (IabHelper.IabAsyncInProgressException e) {
Log.d(TAG, "Error querying inventory. Another async operation in progress.");
}
}
});
}
// Listener that's called when we finish querying the items and subscriptions we own
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
// Is it a failure?
if (result.isFailure()) {
Log.d(TAG, "Failed to query inventory: " + result);
return;
}
Log.d(TAG, "Query inventory was successful.");
/*
* Check for items we own. Notice that for each purchase, we check
* the developer payload to see if it's correct! See
* verifyDeveloperPayload().
*/
// Do we have the premium upgrade?
Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
premium.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mIsPremium = true)
premium.setEnabled(false);
else {
}
}
});
};
};
#Override
public void receivedBroadcast() {
// Received a broadcast notification that the inventory of items has changed
Log.d(TAG, "Received broadcast notification. Querying inventory.");
try {
mHelper.queryInventoryAsync(mGotInventoryListener);
} catch (IabHelper.IabAsyncInProgressException e) {
Log.d(TAG, "Error querying inventory. Another async operation in progress.");
}
}
// User clicked the "Upgrade to Premium" button.
public void onUpgradeAppButtonClicked(View arg0) {
Log.d(TAG, "Upgrade button clicked; launching purchase flow for upgrade.");
/* verifyDeveloperPayload() for more info. Since this is a SAMPLE, we just use
* an empty string, but on a production app you should carefully generate this. */
String payload = "";
try {
mHelper.launchPurchaseFlow(this, SKU_PREMIUM, RC_REQUEST,
mPurchaseFinishedListener, payload);
} catch (IabHelper.IabAsyncInProgressException e) {
Log.d(TAG,"Error launching purchase flow. Another async operation in progress.");
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
if (mHelper == null) return;
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
/** Verifies the developer payload of a purchase. */
boolean verifyDeveloperPayload(Purchase p) {
String payload = p.getDeveloperPayload();
return true;
}
// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
// if we were disposed of in the meantime, quit.
if (mHelper == null) return;
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
return;
}
if (!verifyDeveloperPayload(purchase)) {
Log.d(TAG, "Error purchasing. Authenticity verification failed.");
return;
}
Log.d(TAG, "Purchase successful.");
if (purchase.getSku().equals(SKU_PREMIUM)) {
// bought the premium upgrade!
Log.d(TAG, "Purchase is premium upgrade. Congratulating user.");
Toast toast = Toast.makeText(context, R.string.premium_bought, duration);
toast.show();
mIsPremium = true;
updateUI();
}
}
};
// We're being destroyed. It's important to dispose of the helper here!
#Override
public void onDestroy() {
super.onDestroy();
// very important:
if (mBroadcastReceiver != null) {
unregisterReceiver(mBroadcastReceiver);
}
// very important:
Log.d(TAG, "Destroying helper.");
if (mHelper != null) {
mHelper.disposeWhenFinished();
mHelper = null;
}
}
public void updateUI() {
//TODO: elimina pubblicita
}
}
As I wrote above in te title, I need to start the google purchase
when my premium button is pressed. The android documentation is not very clear on how to do this stuff in particular.
What should I put in my OnClick() method to start the purchase flow?
You should call
mHelper.startSetup
on the button click to start the purchase flow.

IabHelper launchPurchaseFlow google play In-app Billing does not find product

I downloaded the sample app
Got my key from the developer console
Put the proper permissions in my manifest
Nothing helps: I got always product not found...
Thanx - Ralf
here is the code, Java, Android Studio
// Does the user have the professional upgrade? should be an In-App product
private static Boolean _PROFESSIONAL = false;
// Debug tag, for logging
private static final String TAG_BILLING = "BillingService";
// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 10001; // 10002 does not help either...
// The helper object
IabHelper mHelper = null;
static final String SKU_PROFESSIONAL = "com...";
private String base64EncodedPublicKey = "KSRWbpF........... from Google play Developer Console
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
// Create the helper, passing it our context and the public key to verify signatures with
mHelper = new IabHelper(this, base64EncodedPublicKey);
// enable debug logging (for a production application, you should set this to false).
mHelper.enableDebugLogging(true);
// Start setup. This is asynchronous and the specified listener
// will be called once setup completes.
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
#Override
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh no, there was a problem.
return;
}
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
// IAB is fully set up. Now, let's get an inventory of stuff we own.
mHelper.queryInventoryAsync(true, null, mGotInventoryListener);
}
});
}
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG_BILLING, "Query inventory finished.");
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
// Is it a failure?
if (result.isFailure()) {
complain("Failed to query inventory: " + result);
return;
}
// Do we have the premium upgrade?
Purchase premiumPurchase = inventory.getPurchase(SKU_PROFESSIONAL);
_PROFESSIONAL = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
}
};
// User clicked the menu upgrade professional
private void Upgrade() {
String payload = sMyPurchaseToken;
// tested, but no help
// define IabHelper.flagEndAsync() as public, and add iabHelper.flagEndAsync() before iabHelper.launchPurchaseFlow(...)
// mHelper.flagEndAsync();
// could be tested: this, "android.test.purchased", 10002
/////////// here the program shows the Google Play message that the programm does not exist... or is not configured for payment...
mHelper.launchPurchaseFlow(MyActivity.this, SKU_PROFESSIONAL, RC_REQUEST, mPurchaseFinishedListener, payload);
//mHelper.launchPurchaseFlow(this, "android.test.purchased", 10002, is ok
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG_BILLING, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
if (mHelper == null) return;
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
}
else {
}
}
boolean verifyDeveloperPayload(Purchase p) {
String payload = p.getDeveloperPayload();
return true;
}
// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
// if we were disposed of in the meantime, quit.
if (mHelper == null) return;
if (result.isFailure()) {
complain("Error purchasing: " + result);
setWaitScreen(false);
return;
}
if (!verifyDeveloperPayload(purchase)) {
complain("Error purchasing. Authenticity verification failed.");
setWaitScreen(false);
return;
}
if (purchase.getSku().equals(SKU_PROFESSIONAL)) {
_PROFESSIONAL = true;
}
}
};
// Called when consumption is complete
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
Log.d(TAG_BILLING, "Consumption finished. Purchase: " + purchase + ", result: " + result);
// if we were disposed of in the meantime, quit.
if (mHelper == null) return;
if (result.isSuccess()) {
}
else {
complain("Error while consuming: " + result);
}
}
};

Categories