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();
}
这背后的想法是,我有月订阅我想要检索,如果他订阅或不订阅。如果他订阅了我将共享优先付为1,如果不是“”。
这样做吗?如果我现在购买,我能做到正确吗?如果我取消订阅怎么办?我是否已经列入名单?
答案 0 :(得分:0)
关于this手册,您可以检测用户是否使用订阅
getBuyIntent()
。
它产生purchaseState = 0
。
我只建议每次用户启动应用时检测状态。
您可以在developerPayload
中手动设置订阅的时间长度。
我建议不要使用共享偏好。或使用encription保护您的数据,以保护您的应用。