首先,我使用了来自http://www.tutorialsface.com/2016/05/implementing-remove-ads-in-app-purchases-in-android-tutorial-example/的想法,有一个单独的类来处理 InApp 计费.
我开始计费的班级已经有一个 onActivityResult 方法,我将其更改为:
@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.");
}
}
首先,我想获取主 google 帐户并与当前日期一起加密,然后开始计费过程。但是在我收到电子邮件的对话框前面,我有 InApp Billing 的对话框。
所以我想把StartBilling的方法放在Activity Result里面。
但即使我首先收到电子邮件对话框,我也会在 mHelper 上得到一个空值,所以接下来什么也不会发生。如何解决这个问题?
我应该执行以下操作吗?:
@Override
protected void onResume() {
super.onResume();
if(possibleEmail!=null)
{
startBilling.purchaseRemoveAds(possibleEmail);
}
}