Google 的应用内结算示例 com.example.android.trivialdrivesample.MainActivity 包含以下代码:
@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.");
}
}
这看起来有点危险,因为在 mHelper 初始化之前,onActivityResult 不会按预期运行。似乎最好放弃 if (mHelper == null) return
以支持 if (mHelper == null || !mHelper.handleActivityResult(requestCode, resultCode, data))
,即,
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (mHelper == null || !mHelper.handleActivityResult(requestCode, resultCode, data))
super.onActivityResult(requestCode, resultCode, data);
}
原始代码真的很危险吗?还是我理解错了?
最佳答案
嘿,从 10 天开始,我还致力于 InApp Purchase,我已经成功地集成到我现有的应用程序中,并准备好让它上线。最初,当我开始这样做时,我从 here 下载了名为“Trivial Drive”的 Google InApp Billing Example。 .
但它对我帮助不大,因为它有很多问题和错误,所以我决定使用新的 v3 api 从头开始自己做,你可以找到 here .本教程有清晰的解释,可以帮助您,如果您有时间,请参阅 this youtube 视频,其中谷歌员工清楚地解释了如何集成它。
此外,如果您想要快速示例,我有一个示例应用程序,您可以从 here 下载.
以下视频还介绍了如何集成 InApp Purchase。请通过它。
关于android - Google 的应用内计费示例(普通驱动器)的 onActivityResult 方法中存在错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26294683/