私はAndroidが初めてで、私のアプリのアプリ課金を実装しようとしています。私が持っているのは、あなたをInAppBillingActivityに連れて行くボタンです。アクティビティはそのことです。私がしたいのは、購入が成功したときに、そのアクティビティにあなたを連れてきたボタンが消えてしまうことです。私はそれを消すことができません、そして、私はそれを正しくやっていないかもしれません。私はそれが来た断片に戻って戻るボタンを押す必要があり、それは正しく行っていないようだ。だからここに私のコードです:私はボタンが消える取得しようとするすべてのさまざまな方法をしようとしているが、私はそれを実現することができませんAndroid - アプリ内課金が正常に完了した後にボタンが消えるようにする
private InAppBillingActivity activity;
public Button btnPurchase;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
btnPurchase = (Button) rootView.findViewById(R.id.btnPurchase);
activity = new InAppBillingActivity();
setOnClick();
//tried to do it this way
if (activity.isPurchased == true){
btnPurchase.setVisibility(View.GONE);
}
}
public void setOnClick() {
btnPurchase.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(CheckListGatherFragment.this.getActivity(), InAppBillingActivity.class);
startActivity(intent);
//tried doing it this way
if (activity.isPurchased == true){
btnPurchase.setVisibility(View.GONE);
}
}
});
}
//tried doing it this way
@Override
public void onResume() {
super.onResume();
if (activity.isPurchased == true){
btnPurchase.setVisibility(View.GONE);
}
}
:ここ
public class InAppBillingActivity extends AppCompatActivity {
private static final String TAG = "com.android.inappbilling";
public IabHelper mHelper;
private Button btnInAppBilling;
public boolean isPurchased;
private CheckListGatherFragment checkListGatherFragment;
static final String ITEM_SKU = "android.test.purchased";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_in_app_billing);
btnInAppBilling = (Button) findViewById(R.id.btnInAppBilling);
checkListGatherFragment = new CheckListGatherFragment();
String base64EncodedPublicKey = "";
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result)
{
if (!result.isSuccess()) {
Log.d(TAG, "In-app Billing setup failed: " +
result);
} else {
Log.d(TAG, "In-app Billing is set up OK");
}
}
});
}
public void buyClick(View view){
mHelper.launchPurchaseFlow(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);
}
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase)
{
if (result.isFailure()) {
// Handle error
return;
}
else if (purchase.getSku().equals(ITEM_SKU)) {
consumeItem();
btnInAppBilling.setEnabled(false);
}
}
};
public void consumeItem() {
mHelper.queryInventoryAsync(mReceivedInventoryListener);
}
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
// Handle failure
return;
} else {
mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
mConsumeFinishedListener);
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase,
IabResult result) {
if (result.isSuccess()) {
//Here is where I am trying to get it to disappear
checkListGatherFragment.btnPurchase.setVisibility(View.GONE);
//Tried a boolean to get it to disappear
isPurchased = true;
} else {
// handle error
return;
}
}
};
@Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
}
は私のフラグメントの一部であります。購入は成功しましたが、ボタンは消えません。どんな助けでも大歓迎です。ありがとう!
応答ありがとう。私はあなたが提案したものを試しても機能しませんでしたが、購入に間違いがあります:06-27 12:59:54.459 13159-13159/mk E/IABUtil/Security:購入確認に失敗しました:データがありません。 06-27 12:59:54.459 13159-13159/mk E/IabHelper:アプリ内課金エラー:SKUの購入署名検証に失敗しましたandroid.test.purchased購入が正しく行われていない可能性があります。それは購入されたが、検証は正しくないと言います。どう思いますか?今、テスト目的で使っています。 – Karna
これについてはあまり詳しく説明できませんが、以前はアプリ内課金で働いたことがありません。しかし、そのエラーの説明から、おそらく間違った公開鍵を使用していると思います。 – Tharkius
ありがとう!コードは機能しました!私はその問題を解決したstackoverflowのページを見つけました。 – Karna