2

購入画面を呼び出すと、アプリ内製品を購入でき、すべて正常に機能しますが、ユーザーがアプリを離れて製品を表示するために戻ったときに、再度購入するように求め続けます。

ユーザーがアプリを購入したときにストア画面が表示されなくなり、製品にアクセスできるようにする方法を知る必要があります。ユーザーがアプリを購入すると、新しいアクティビティにアクセスできるようにアプリが設計されています組み込まれている機能

誰かが助けてくれたら、私はとても感謝しています

私はこのチュートリアルを使用しました。これは、始めるのに非常に役立ちました: [TUT] Simple InApp Billing / Payment By blundell

これが私のコードです

      package com.IrishSign.app;

    import java.util.Locale;

    import com.IrishSign.app.BillingHelper;
    import com.IrishSign.app.R;
    import com.IrishSign.app.BillingService;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.Dialog;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.database.Cursor;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Handler;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.Toast;

    public class IrishSignAppActivity extends Activity implements OnClickListener {
        private static final String TAG = "BillingService";

        private Context mContext;
        private ImageView purchaseableItem;
        private Button purchaseButton;

    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        Log.i("BillingService", "Starting");
        setContentView(R.layout.main);
        mContext = this;
        Button A = (Button) findViewById(R.id.alphabet);
        Button purchaseableItem = (Button) findViewById(R.id.topics);
        Button Intro = (Button) findViewById(R.id.intro);
        Button G = (Button) findViewById(R.id.about);

        purchaseableItem.setOnClickListener(this);
        startService(new Intent(mContext, BillingService.class));
        BillingHelper.setCompletedHandler(mTransactionHandler);

        A.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent1 = new Intent("com.IrishSign.app.alpha");
                startActivity(intent1);
            }
        });

        Intro.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent intent1 = new Intent("com.IrishSign.app.Intro");
                startActivity(intent1);
            }
        });

        G.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                AlertDialog alertDialog = new AlertDialog.Builder(
                        IrishSignAppActivity.this).setCancelable(false)
                        .create(); // Reads Update
                alertDialog.setTitle("Welcome");
                alertDialog.setMessage("-----");// 

                alertDialog.setButton("Continue",
                        new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int arg1) {
                                Intent intent5 = new Intent(
                                        IrishSignAppActivity.this,
                                        IrishSignAppActivity.class);

                            }
                        });

                alertDialog.show(); // <-- Shows dialog on screen.
            }

        });

    }

    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()) {
                Intent intent = new Intent("com.IrishSign.app.Topics");
                startActivity(intent);
            }
        };

    };

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.topics:
            if (BillingHelper.isBillingSupported()) {
                BillingHelper.requestPurchase(mContext,
                        "com.blundell.item.passport");
                // android.test.purchased or android.test.canceled or
                // android.test.refunded or com.blundell.item.passport
            } else {
                Log.i(TAG, "Can't purchase on this device");
                purchaseButton.setEnabled(false); // XXX press button before
                                                    // service started will
                                                    // disable when it shouldnt
            }

            break;
        default:
            // nada
            Log.i(TAG, "default. ID: " + v.getId());
            break;
        }

    }

    @Override
    protected void onPause() {
        Log.i(TAG, "onPause())");
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        BillingHelper.stopService();
        super.onDestroy();
    }
}
4

1 に答える 1

0

restoreTransactions を使用して、アプリケーションの開始時期を確認できます。管理対象製品またはサブスクリプションを使用したことがある場合、ユーザーのすべての詳細を取得できるのはあなただけです。

管理対象外の製品については、Google が管理する詳細はありません。

したがって、これをメインアクティビティで呼び出します

mBillingService = new BillingService();
mBillingService.setContext(this);
mBillingService.restoreTransactions();

これを ResponseHandler クラスで呼び出すと、 purchaseResponse メソッドが 1 つあります。

purchaseResponse(final Context context,
        final PurchaseState purchaseState, final String productId,
        final String orderId, final long purchaseTime,
        final String developerPayload, final String purchaseToken) {
 }

すべての詳細が返されます。

その後、購入状態を確認できます

       if (purchaseState == PurchaseState.PURCHASED) {

        } else if (purchaseState == PurchaseState.REFUNDED) {

        } else if (purchaseState == PurchaseState.CANCELED) {

        }
于 2012-12-10T11:18:33.687 に答える