android - Google 的应用内计费示例(普通驱动器)的 onActivityResult 方法中存在错误?

标签 android in-app-billing android-billing

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。请通过它。

https://www.youtube.com/watch?v=-h2ESH71hAI

关于android - Google 的应用内计费示例(普通驱动器)的 onActivityResult 方法中存在错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26294683/

相关文章:

android - 使用 androidx.preference.PreferenceScreen 和 PreferenceScreen 的区别

android - 如何在 Android InAppBilling 中升级/降级订阅?

android - 包 IInAppBillingService 不存在

java - In-app billing acknowledgePurchase issue [使用google play in-app billing library]

android - 我怎样才能找出用户的谷歌播放国家?

android - 静态代码中的应用内购买错误

Android InApp Billing v3,谷歌播放对话框未显示

Android Facebook SDK - 无法接收访问 token

android - 在 Android 上使用全局数据的推荐方式是什么?

java - Android Google API 客户端未连接