【问题标题】:IN APP Purchase how to retrieve monthly subscriptionIN APP购买如何找回包月
【发布时间】:2018-03-01 10:02:50
【问题描述】:
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "subs", null);
                            int response = ownedItems.getInt("RESPONSE_CODE");
                             if (response == 0) {

                                ArrayList<String> ownedSkus =
                                        ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
                                ArrayList<String> purchaseDataList =
                                        ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
                                ArrayList<String> signatureList =
                                        ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
                                String continuationToken =
                                        ownedItems.getString("INAPP_CONTINUATION_TOKEN");

//
                                if(purchaseDataList.size() == 0){
                                    paid = false;
                                    App.paid = false;
                                    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit();
                                    editor.putString("paid", "");
                                    editor.commit();
                                }
                                for (int i = 0; i < purchaseDataList.size(); ++i) {
                                    String purchaseData = purchaseDataList.get(i);
                                    String signature = signatureList.get(i);
                                    String sku = ownedSkus.get(i);
                                    try {
                                        JSONObject jo = new JSONObject(purchaseData);
                                        String sku1 = jo.getString("productId");
                                        if (sku1.trim().toLowerCase().equals("paid2")) {
                                            paid = true;
                                            App.paid = true;
                                            SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit();
                                            editor.putString("paid", "1");
                                            editor.commit();

                                            Handler handler = new Handler();
                                            handler.postDelayed(new Runnable() {
                                                @Override
                                                public void run() {
                                                    try {
                                                        stopAds();
                                                    } catch (Exception e) {

                                                    }
                                                }
                                            }, 2000);
                                        }
                                        else
                                        {
                                            paid = false;
                                            App.paid = false;
                                            SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit();
                                            editor.putString("paid", "");
                                            editor.commit();
                                        }
                                    } catch (JSONException e) {
                                        //   alert("Failed to parse purchase data.");
                                        e.printStackTrace();
                                    }

这背后的想法是,如果他订阅或不订阅,我想检索每月订阅。如果他订阅了,我将 sharedpreference 支付为 1,如果不是 ""。

这样可以吗?如果我现在买怎么办,我买对了吗?如果我取消订阅怎么办..我是否会进入列表?

【问题讨论】:

    标签: android payment


    【解决方案1】:

    关于this手册,您可以检测用户是否订阅使用 getBuyIntent().

    它产生purchaseState = 0

    我只是建议在用户每次启动应用时检测状态。 您可以在developerPayload中手动设置订阅时长。 我建议不要使用共享首选项。或者使用加密来保护您的数据以保护您的应用。

    【讨论】:

      猜你喜欢
      • 2011-12-10
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多