First of all I used the idea from http://www.tutorialsface.com/2016/05/implementing-remove-ads-in-app-purchases-in-android-tutorial-example/ having a separate class for dealing InApp billing.
My class from which I start the billing had an already onActivityResult method which I changed it to:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (mHelper == null) return;
if (!mHelper.handleActivityResult(requestCode, resultCode, data))
{
if(requestCode==3)
{
// Construct the data source
ArrayList<Service> arrayOfServices = new ArrayList<Service>();
arrayOfServices = db.getAllServices();
// Create the adapter to convert the array to views
CatalogueAdapter adapter = new CatalogueAdapter(this, arrayOfServices);
// Attach the adapter to a ListView
myServices.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
if (requestCode == 1111 && resultCode == RESULT_OK)
{
String emailAddress = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm");
String formattedDate = df.format(c.getTime());
possibleEmail=md5(emailAddress + formattedDate);
startBilling.purchaseRemoveAds(possibleEmail);
}
}else
{
//Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
First of all,I want to get the main google account and encrypted together with the current date and then start the Billing process. But in front of the dialog from which I get the email I have the dialog of InApp Billing.
So I thought to place the method of StartBilling inside the Activity Result.
But even if I get the email dialog first I get a null on mHelper so nothing happens next. How To fix this?
Shall I do the following?:
@Override
protected void onResume() {
super.onResume();
if(possibleEmail!=null)
{
startBilling.purchaseRemoveAds(possibleEmail);
}
}