我正在使用anjlab / android-inapp-billing库进行应用内购买。在我的活动中第一次尝试单击<< [Purchase Button时,我可以看到出现了要购买的对话框。
在此对话框中,我得到testingId
。单击
购买按钮时,我看到了两个选项,然后确定。
第一次尝试成功。现在,如果我单击
[购买按钮
,则是第一个成功购买的物品,现在此对话框不会出现。为什么不显示此dialog
?这是我的代码
final AlertDialog.Builder builder2 = new AlertDialog.Builder(StartActivity.this);
LayoutInflater inflater = getLayoutInflater();
View dialogLayout = inflater.inflate(R.layout.adremover_layout, null);
builder2.setTitle("Clear Ads");
builder2.setMessage("Buy Products");
builder2.setView(dialogLayout);
builder2.setIcon(R.drawable.dupiconf);
Button btn_buy1 = (Button)dialogLayout.findViewById(R.id.buyitem_btn1);
Button btn_buy2 = (Button)dialogLayout.findViewById(R.id.buyitem_btn2);
Button btn_buy3 = (Button)dialogLayout.findViewById(R.id.buyitem_btn3);
btn_buy1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editor1 = getSharedPreferences(FIRST_BUY, MODE_PRIVATE).edit();
editor1.putString("product", "item1");
editor1.apply();
getpurchaseitem = "itm1";
bp.purchase(StartActivity.this, "android.test.purchased");
}
});
btn_buy2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editor1 = getSharedPreferences(FIRST_BUY, MODE_PRIVATE).edit();
editor1.putString("product", "item2");
editor1.apply();
getpurchaseitem = "itm2";
bp.purchase(StartActivity.this, "android.test.purchased");
}
});
btn_buy3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editor1 = getSharedPreferences(FIRST_BUY, MODE_PRIVATE).edit();
editor1.putString("product", "item3");
editor1.apply();
getpurchaseitem = "itm3";
bp.purchase(StartActivity.this, "android.test.purchased");
}
});
alert2 = builder2.create();
alert2.show();
即使在卸载应用程序后,也不会出现购买对话框。
@Override public void onProductPurchased(@NonNull String productId, @Nullable TransactionDetails details) { if(getpurchaseitem == "itm1") { CancelAlarm(); } else if (getpurchaseitem == "itm2") { CancelAlarm(); } else if(getpurchaseitem == "itm3") { CancelAlarm(); } }