Am I getting the steps right for verifying a user's Android in-app subscription?

前端 未结 7 1442
刺人心
刺人心 2020-11-28 21:06

I am making an app that does not require a user account/login, and allows the user to purchase a subscription. I want to use the Google Play Developer API to verify whether

7条回答
  •  北海茫月
    2020-11-28 21:43

    I may misunderstand your question, but I don't see a reason for you to be using the links you're referencing to get In-App Billing for an Android app working. This page is much more helpful:

    http://developer.android.com/guide/google/play/billing/index.html

    You can try out the demo application they include (Dungeons -- http://developer.android.com/guide/google/play/billing/billing_integrate.html#billing-download). That uses products (one-time purchases) rather than subscriptions, but you should be able to modify to test for what you want.

    I think the key, for you, would be the restoreTransactions method they provide in the sample to see if the Google Play account has any subscriptions for your app:

    @Override
    public void onRestoreTransactionsResponse(RestoreTransactions request, int responseCode) {
        if (responseCode == BillingVars.OK) {                        
            // Update the shared preferences so that we don't perform a RestoreTransactions again.
            // This is also where you could save any existing subscriptions/purchases the user may have.
            SharedPreferences prefs = getSharedPreferences(my_prefs_file, Context.MODE_PRIVATE);
            SharedPreferences.Editor edit = prefs.edit();
            edit.putBoolean(DB_INITIALIZED, true);
            edit.commit();
        } else {
            Log.e(TAG, "RestoreTransactions error: " + responseCode);
        }
    }
    

提交回复
热议问题