android - 在 BillingProcessor.purchase 后应用计费不显示弹出消息
问题描述
我对 Android 中的应用内计费仍然不熟悉。我已经尝试过与本教程完全相同的方法,但从未弹出。这是链接
这是我的代码
主要活动
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" />
即使我尝试与教程完全相同,我也真的被困住了。你能帮忙看看问题出在哪里。
解决方案
在最新版本的 google pay 中,许可证密钥和产品 ID不能再为空。您必须使用您的产品 ID 和开发人员许可证密钥创建一个 alpha 版本,就像它们在控制台中的方式一样。
此外,您必须在发布 alpha 版本后等待大约30 分钟才能测试您的计费。
希望有帮助!!
(确保您已添加 INTERNET 权限;将 build.gradle 中的“+”号替换为您将在更改日志中找到的版本)
推荐阅读
- flutter - 如何在flutter中自定义水平时间选择器?
- laravel - Wordpress 面临的帖子名称永久链接问题无法正常工作,但在将网站迁移到 live aws elastic beanstalk 后,普通链接正在工作
- android - 我可以做什么?在这个错误中 Fastlane [!] Google Api Error: Invalid request - UploadException:ADHOC_PACKAGE_NAME_MISMATCH [[]]
- fortify - 强化报告生成器
- php - Woocommerce - 获取子类别的父类别名称
- reactjs - 如何从 React 中的对象数组中打字
- flutter - 如何使用 PaginatedDataTable 更改列的背景颜色
- flutter - 为什么补间动画总是从 0.0 运行到 1.0?
- android - 仅使用电话号码向 Android 和 iOS 发送 PUSH 通知
- nestjs - 在 TypeORM 查询中有不必要的 leftJoin