Android InApp结算错误:IAB活动结果中的空数据

时间:2017-08-02 19:38:06

标签: android

我一直在

  

IAB活动结果中的空数据

我正在尝试使用Android Trivial示例在我的应用中实现应用内结算。我做错了什么?

public class Donate extends AppCompatActivity {
private static final String TAG =
        "TAG HERE";
IabHelper mHelper;
static final String ITEM_SKU = "android.test.purchased";

private Toolbar toolbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.setContentView(R.layout.activity);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view) {
            finish();
        }
    });

    //Google play purchase test
    String base64EncodedPublicKey =
            "<My base 64 key>";
    mHelper = new IabHelper(this, base64EncodedPublicKey);
    Button button = (Button) findViewById(R.id.donate_btn);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            mHelper.launchPurchaseFlow(Donate.this, ITEM_SKU, 10001,
                    mPurchaseFinishedListener, "mypurchasetoken");
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
                                Intent data)
{
    if (!mHelper.handleActivityResult(requestCode,
            resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

2 个答案:

答案 0 :(得分:1)

自从你开始以来,我还建议你留意Google Play Billing Library。它是开发预览版,但我会考虑它,只是为了让它更容易迁移。

正如Kavach所说,检查您是否添加了产品。 并且,添加它并告诉我们你得到了什么:

if (mHelper != null) mHelper.dispose();

最后,请记住在onDestroy中处理帮助程序:

{{1}}

答案 1 :(得分:1)

您似乎尚未在Google Play开发者控制台上创建产品。请查看以下教程以帮助您完成此过程。这些是在Android Studio中实施应用内结算的分步指南:

http://www.techotopia.com/index.php/An_Android_Studio_Google_Play_In-app_Billing_Tutorial

https://developer.android.com/google/play/billing/index.html