0

このチュートリアルからアプリ内課金を実装しました。購入するアイテムは、カスタム背景を設定する機能です。うまく機能しますが、アプリをアンインストールして再インストールする(またはユーザー設定をクリアする)と、誰かがアプリ内アイテムを既に購入していることを確認する方法がわかりません。

    public void buySelected() {

    if (backgroundColorsPurchased == true) {
        this.colorChangeDialog(); //if user has already purchased, just call the dialog instead of re-buying.
        //if the person has cleared their prefs, they'll have to be online to re-verify that they did indeed buy the item.

    }else{
        if(BillingHelper.isBillingSupported()){
            BillingHelper.requestPurchase(mContext, "background.colors");
            BillingHelper.setCompletedHandler(mTransactionHandler);

        } else {
            Log.i(TAG,"Can't purchase on this device");

        }
    }
}

次に、ハンドラーがあります。

    public Handler mTransactionHandler = new Handler(){
    public void handleMessage(android.os.Message msg) {
        Log.i(TAG, "Transaction complete");
        Log.i(TAG, "Transaction status: "+BillingHelper.latestPurchase.purchaseState);
        Log.i(TAG, "Item purchased is: "+BillingHelper.latestPurchase.productId);

        if(BillingHelper.latestPurchase.isPurchased()){
        //this is where we show the stuff that the person purchased. In this case, the dialog to change the background colour.
            backgroundColorsPurchased = true; //just setting this to true so that the next time somebody clicks the donate button it'll just open the dialog.

            //call the change background dialog
            colorChangeDialog();

        }else{
            //fail
            Toast.makeText(getApplicationContext(), "Fail", Toast.LENGTH_SHORT).show();

        }
    }

 };

アイテムが以前に購入されたことを確認するにはどうすればよいですか?マーケットは、「このアイテムをすでに購入したか、購入がまだ保留中です」というダイアログウィンドウを表示し続けます。if(BillingHelper.latestPurchase.isPurchased()){ハンドラー内にない場合、フォースを閉じるようなものを使用しようとすると。

4

3 に答える 3

0

詳細については、restoreTransactions を呼び出す必要があります。詳細については、Android がアプリ内課金用に提供しているデフォルトの例をご覧ください。

于 2011-08-13T17:08:59.743 に答える
0

設定/データが消去された場合は、トランザクションを復元する必要があります。これにより、ユーザーが購入したアイテムの情報が送信され、通常どおり承認を処理できます。これを行う方法については、リファレンスを読み、Dungeons サンプルを確認してください。

于 2011-08-13T17:10:08.357 に答える