2016-08-25 2 views
0

내 앱 인앱 결제에 문제가 있습니다. 나는 그것이 지난 주 동안 잘 작동하고 있다고 생각했지만 예기치 않은 결과를 얻고 있습니다.Android 인앱 결제로 구매 문제 발생

판매 품목은 약 10 개입니다. 인벤토리를 구입/쿼리 할 때 각 항목은 공유 된 값을 true로 설정합니다. 하나의 항목은 "모두 구입"버튼입니다. 구입하면 다른 모든 항목의 값을 true로 설정하는 것이 좋습니다. 이것은 잘 작동했는데 문제는 구매할 새 항목을 추가 할 때 발생합니다. "모두 사다"는 사람들에게도 접근 권한을 주어야하지만 그렇지 않은 것 같습니다.

여전히 필요한 정보를 보여주는 동안 가능한 한 내 코드로 간단하게하려고합니다

: (모두 인앱 구매가 설정) BaseActivity.java :

//SKU FOR our products 
static final String SKU_W31 = "workout_31"; 
static final String SKU_W32 = "workout_32"; 
static final String SKU_W37 = "workout_37"; 
static final String SKU_ALL = "all_workouts"; 

//is paid? 
public boolean m31paid = false; 
public boolean m32paid = false; 
public boolean m37paid = false; 
public boolean mAllPaid = false; 

IabHelper mHelper; 
IabBroadcastReceiver mBroadcastReceiver; 

    @Override 
protected void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); 
mHelper = new IabHelper(this, base64EncodedPublicKey); 
    //SET FALSE FOR LIVE APP 
    mHelper.enableDebugLogging(false); 

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { 
     public void onIabSetupFinished(IabResult result) { 
      if (!result.isSuccess()) { 
       Log.d(LOG, "Problem setting up in app billing: " + result); 
      } else Log.d(LOG, "set up correctly!"); 
      if (mHelper == null) return; 

      mBroadcastReceiver = new IabBroadcastReceiver(BaseActivity.this); 
      IntentFilter broadcastFilter = new IntentFilter(IabBroadcastReceiver.ACTION); 
      registerReceiver(mBroadcastReceiver, broadcastFilter); 

      // IAB is fully set up. Now, let's get an inventory of stuff we own. 
      Log.d(LOG, "Setup successful. Querying inventory."); 

      try { 
       mHelper.queryInventoryAsync(mGotInventoryListener); 
      } catch (IabHelper.IabAsyncInProgressException e) { 
       complain("Error querying inventory. Another async operation in progress."); 
      } 
     } 
    }); 
} 

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { 
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) { 
     Log.d(LOG, "Query inventory finished."); 
     SharedPreferences.Editor editor = getSharedPreferences("my_pref", MODE_PRIVATE).edit(); 

     // Have we been disposed of in the meantime? If so, quit. 
     if (mHelper == null) return; 


Purchase w37Purchase = inventory.getPurchase(SKU_W37); 
     m37paid = (w37Purchase != null && verifyDeveloperPayload(w37Purchase)); 
     Log.d(LOG, "User has workout 37" + (m37paid ? "BOUGHT" : "NOT BOUGHT")); 
     if (w37Purchase != null) { 
      editor.putBoolean("workout37", true); 
      editor.apply(); 
     } 

Purchase w32Purchase = inventory.getPurchase(SKU_W32); 
     m32paid = (w32Purchase != null && verifyDeveloperPayload(w32Purchase)); 
     Log.d(LOG, "User has workout 32" + (m32paid ? "BOUGHT" : "NOT BOUGHT")); 
     if (w32Purchase != null) { 
      editor.putBoolean("workout32", true); 
      editor.apply(); 
     } 

Purchase w31Purchase = inventory.getPurchase(SKU_W31); 
     m31paid = (w31Purchase != null && verifyDeveloperPayload(w31Purchase)); 
     Log.d(LOG, "User has workout 31" + (m31paid ? "BOUGHT" : "NOT BOUGHT")); 
     if (w31Purchase != null) { 
      editor.putBoolean("workout31", true); 
      editor.apply(); 
     } 

Purchase wAllPurchase = inventory.getPurchase(SKU_ALL); 
     mAllPaid = (wAllPurchase != null && verifyDeveloperPayload(wAllPurchase)); 
     Log.d(LOG, "User has " + (mAllPaid ? "BOUGHT" : "NOT BOUGHT")); 
     if (wAllPurchase != null) { 
      editor.putBoolean("workout31", true); 
      editor.putBoolean("workout32", true); 
      editor.putBoolean("workout37", true); 
      editor.apply(); 
     } 

    }}; 

내가 그 방법을을

public void onBuy31ButtonClicked (View arg0) { 
    Log.d(LOG, "Buy 31 button clicked."); 
    if (m31paid) { 
     Toast.makeText(getApplicationContext(), R.string.already_bought, Toast.LENGTH_LONG).show(); 
     return; 
    } 
    Log.d(LOG, "launching purchase for 31"); 
    String payload = ""; 
    try { 
     mHelper.launchPurchaseFlow(this, SKU_W31, RC_REQUEST, mPurchaseFinishedListener, payload); 
    } catch (IabHelper.IabAsyncInProgressException e) { 
     Toast.makeText(getApplicationContext(), R.string.purchase_error, Toast.LENGTH_LONG).show(); 
    } 
} 
public void onBuy32ButtonClicked (View arg0) { 
    Log.d(LOG, "Buy 32 button clicked."); 
    if (m32paid) { 
     Toast.makeText(getApplicationContext(), R.string.already_bought, Toast.LENGTH_LONG).show(); 
     return; 
    } 
    Log.d(LOG, "launching purchase for 32"); 
    String payload = ""; 
    try { 
     mHelper.launchPurchaseFlow(this, SKU_W32, RC_REQUEST, mPurchaseFinishedListener, payload); 
    } catch (IabHelper.IabAsyncInProgressException e) { 
     Toast.makeText(getApplicationContext(), R.string.purchase_error, Toast.LENGTH_LONG).show(); 
    } 
} 
public void onBuy37ButtonClicked (View arg0) { 
    Log.d(LOG, "Buy 37 button clicked."); 
    if (m37paid) { 
     Toast.makeText(getApplicationContext(), R.string.already_bought, Toast.LENGTH_LONG).show(); 
     return; 
    } 
    Log.d(LOG, "launching purchase for 37"); 
    String payload = ""; 
    try { 
     mHelper.launchPurchaseFlow(this, SKU_W37, RC_REQUEST, mPurchaseFinishedListener, payload); 
    } catch (IabHelper.IabAsyncInProgressException e) { 
     Toast.makeText(getApplicationContext(), R.string.purchase_error, Toast.LENGTH_LONG).show(); 
    } 
} 
public void onBuyAllButtonClicked (View arg0) { 
    Log.d(LOG, "Buy all button clicked."); 
    if (m32paid) { 
     Toast.makeText(getApplicationContext(), R.string.already_bought, Toast.LENGTH_LONG).show(); 
     return; 
    } 
    Log.d(LOG, "launching purchase for all"); 
    String payload = ""; 
    try { 
     mHelper.launchPurchaseFlow(this, SKU_ALL, RC_REQUEST, mPurchaseFinishedListener, payload); 
    } catch (IabHelper.IabAsyncInProgressException e) { 
     Toast.makeText(getApplicationContext(), R.string.purchase_error, Toast.LENGTH_LONG).show(); 
    } 
} 

내 mPurchaseFinishedListener :

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { 
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) { 
     Log.d(LOG, "Purchase finished: " + result + ", purchase: " + purchase); 
     SharedPreferences.Editor editor = getSharedPreferences("my_pref", MODE_PRIVATE).edit(); 

     // if we were disposed of in the meantime, quit. 
     if (mHelper == null) return; 

     if (result.isFailure()) { 
      complain("Error purchasing: " + result); 

      return; 
     } 
     if (purchase.getSku().equals(SKU_W30)) { 
      editor.putBoolean("workout30", true); 
      editor.apply(); 
      return; 
     } 
     if (purchase.getSku().equals(SKU_W31)) { 
      editor.putBoolean("workout31", true); 
      editor.apply(); 
      return; 
     } 
     if (purchase.getSku().equals(SKU_W32)) { 
      editor.putBoolean("workout32", true); 
      editor.apply(); 
      return; 
     } 
     if (purchase.getSku().equals(SKU_W37)) { 
      editor.putBoolean("workout37", true); 
      editor.apply(); 
      return; 
     if(purchase.getSku().equals(SKU_ALL)) { 
      editor.putBoolean("workout31", true); 
      editor.putBoolean("workout32", true); 
      editor.putBoolean("workout37", true); 
      editor.apply(); 
      return; 
     } 
내가 해당 버튼의 OnClick에 넣어 구입 데이터가 어디에3210

그리고, 나는 단순히이 if 문은 다음과 같은 부울 값을 확인하는 경우 :

xpandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { 
     SharedPreferences pref = getApplicationContext().getSharedPreferences("my_pref", MODE_PRIVATE); 
     boolean w31 = pref.getBoolean("workout31", false); 
     boolean w32 = pref.getBoolean("workout32", false); 
     boolean w37 = pref.getBoolean("workout37", false); 

if (groupPosition == 2) { 
       if(w31 == true) { 
        if (childPosition == 0) { 
         Intent intent = new Intent(getApplicationContext(), WorkoutDaysActivity.class); 
         intent.putExtra("workout", "w31w1"); 
         startActivity(intent); 
        } 
        if (childPosition == 1) { 
         Intent intent = new Intent(getApplicationContext(), WorkoutDaysActivity.class); 
         intent.putExtra("workout", "w31w2"); 
         startActivity(intent); 
        } 
       }else Toast.makeText(getApplicationContext(), "Sorry, but you need to purchase these workouts from the menu.", Toast.LENGTH_LONG).show(); 
     } 

모든 하위 항목은 W32과 W37과 W31을 전환, 위와 같은 코드가 있습니다.

코드를 줄이기 위해 대부분의 구매 항목을 가져 왔지만 여전히 요점을 얻지 만 근본적으로 31 번과 32 번이 추가 된 다음 구입 버튼을 모두 사용했습니다. 그러나 나중에 업데이트 37을 추가하고 내 이론은 부울 값이 모든 운동을 쿼리하고 구매 한 것을 확인할 때 변경된다는 것입니다. 실제로 확장형 목록보기에서 37 번을 클릭하면 구매가 필요하다고 말하는 축배가 나옵니다. 구매 페이지로 가서 "모두 구입"을 클릭하면 이미 구입 한 것을 나타내는 축배를 얻습니다.

내 코드에 문제가있는 사람이 있습니까? 고마워,이 큰 문제가 발생합니다!

답변

0

비동기 작업의 원인으로 경쟁 조건이있을 수 있습니다. 확장형 목록보기를 사용하는 활동은 SharedPreferences의 모든 변경 사항에 등록해야합니다.