在App billing中,在BillingProcessor.purchase之后没有显示弹出消息

问题描述 投票:0回答:1

我还不熟悉Android中的应用内结算功能。我已经尝试了与本教程完全相同但从未得到弹出窗口。这是链接

GitHub

Tutorial Video

这是我的代码

主要信息

public class MainActivity extends AppCompatActivity implements BillingProcessor.IBillingHandler {
    BillingProcessor bp;
    Button purchase;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        bp = new BillingProcessor(this, null, this);
        purchase = (Button) findViewById(R.id.purchase);

        purchase.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bp.purchase(MainActivity.this, "android.test.purchased");
            }
        });

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bp.purchase(MainActivity.this, "android.test.purchased");
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onProductPurchased(@NonNull String productId, @Nullable TransactionDetails details) {
        showToast("You Have Purchased The Product");
    }

    @Override
    public void onPurchaseHistoryRestored() {

    }

    @Override
    public void onBillingError(int errorCode, @Nullable Throwable error) {
        showToast("An Error Has Occurred");
    }

    @Override
    public void onBillingInitialized() {

    }

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

    @Override
    public void onDestroy(){
        if(bp != null){
            bp.release();
        }
        super.onDestroy();
    }

    private void showToast(String message) {
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
}

我在build.gradle APP中添加了这个

compile 'com.anjlab.android.iab.v3:library:1.0.+'

在AndroidManifest中,我也添加了计费权限

<uses-permission android:name="com.android.vending.BILLING" />

即使我试着和教程完全一样,我真的很困难。你能帮忙解决问题所在吗?

android in-app-billing
1个回答
0
投票

在最新版本的Google Pay中,许可证密钥和产品ID不能再为null。您必须使用产品ID和开发人员许可证密钥创建alpha版本,就像他们在控制台中一样。

此外,在发布Alpha版本以测试结算后,您必须等待约30分钟。

希望有所帮助!!

(确保您已添加INTERNET权限;将build.gradle中的“+”符号替换为您在更改日志中找到的版本)

© www.soinside.com 2019 - 2024. All rights reserved.