2015-01-08 3 views
0

일부 인앱 결제 기능이있는 첫 번째 Android 앱 중 하나에서 작업하고 있습니다. 지난 3 일 동안 개발자 라이선스를 구매 한 후 이러한 인앱 구매를 추가하는 방법을 조사했습니다.android.test.preased 재설정 중 오류가 발생했습니다.

http://www.techotopia.com/index.php/An_Android_Studio_Google_Play_In-app_Billing_Tutorial

테스트 프로그램이 잘 작동 : 나는 테스트 프로그램을 성공으로 저를 이끌어 가이드를 우연히 발견했다. 그러나 NavigationDrawerFragment 프로그램에이 가이드를 적용했을 때 몇 가지 문제가있었습니다. 제목에서 말한 것처럼 SKU로 android.test.purchased를 사용하고 있으며 매시간 테스트 구매를 사용하게하는 것 같습니다. 내가 얻을

다른 시간 "에서 인앱 결제 오류 : 아이템을 구매 할 수 없습니다, 오류 응답 : 7 : 이미 소유 항목"

나는 매니페스트 파일에 청구 권한을 추가 한, 나는이 변경을 만들었습니다 (가이드 다음)를 Security.java 파일 : - 한 OnCreate -

public static boolean verifyPurchase(String base64PublicKey, 
            String signedData, String signature) { 
    if (TextUtils.isEmpty(signedData) || 
      TextUtils.isEmpty(base64PublicKey) || 
      TextUtils.isEmpty(signature)) { 
     Log.e(TAG, "Purchase verification failed: missing data."); 
     if (BuildConfig.DEBUG) { 
      return true; 
     } 
     return false; 
    } 

MainActivity.java Log.d 코드는 // 목적에

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    String base64EncodedPublicKey = 
      "My key that i almost pasted in here :P"; 

    mHelper = new IabHelper(this, base64EncodedPublicKey); 

    mHelper.startSetup(new 
           IabHelper.OnIabSetupFinishedListener() { 
            public void onIabSetupFinished(IabResult result) 
            { 
             if (!result.isSuccess()) { 
              //Log.d(TAG, "In-app Billing setup failed: " + 
                //result); 
             } else { 
              //Log.d(TAG, "In-app Billing is set up OK"); 
             } 
            } 
           }); 

    mNavigationDrawerFragment = (NavigationDrawerFragment) 
      getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); 
    mTitle = getTitle(); 

    // Set up the drawer. 
    mNavigationDrawerFragment.setUp(
      R.id.navigation_drawer, 
      (DrawerLayout) findViewById(R.id.drawer_layout)); 
} 
MainActivity.java의

나머지 즉, drawerFragment와 함께 할 필요가 없습니다 :

private static final String TAG = "com.example.inappbilling"; 
static final String ITEM_SKU = "android.test.purchased"; 

public void buyClick(View view) { 
    mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001, 
      mPurchaseFinishedListener, "mypurchasetoken"); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, 
           Intent data) 
{ 
    if (!mHelper.handleActivityResult(requestCode, 
      resultCode, data)) { 
     super.onActivityResult(requestCode, resultCode, data); 
    } 
} 

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener 
     = new IabHelper.OnIabPurchaseFinishedListener() { 
    public void onIabPurchaseFinished(IabResult result, 
             Purchase purchase) 
    { 
     if (result.isFailure()) { 
      // Handle error 
      return; 
     } 
     else if (purchase.getSku().equals(ITEM_SKU)) { 
      consumeItem(); 
     } 
    } 
}; 


public void consumeItem() { 
    mHelper.queryInventoryAsync(mReceivedInventoryListener); 
} 

IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener 
     = new IabHelper.QueryInventoryFinishedListener() { 
    public void onQueryInventoryFinished(IabResult result, 
             Inventory inventory) { 

     if (result.isFailure()) { 
      // Handle failure 
     } else { 
      mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU), 
        mConsumeFinishedListener); 
     } 
    } 
}; 


IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = 
     new IabHelper.OnConsumeFinishedListener() { 
      public void onConsumeFinished(Purchase purchase, 
              IabResult result) { 

       if (result.isSuccess()) { 
        //clickButton.setEnabled(true); 
        Context.MODE_PRIVATE); 

        //Never had this code actually run before, could contain errors 
        //but those aren't the issue to my knowledge. 
        SharedPreferences pref = MainActivity.this.getSharedPreferences("MyPref", 
        SharedPreferences.Editor editor = pref.edit(); 
        editor.putBoolean("BoughtTabard",true); 
        editor.commit(); 
        FragmentManager fragmentManager = getSupportFragmentManager(); 
        fragmentManager.beginTransaction() 
          .replace(R.id.container, TabardGuideNeedToBuy.newInstance(8)) 
          .commit(); 

       } else { 
        // handle error 
       } 
      } 
     }; 


@Override 
public void onDestroy() { 
    super.onDestroy(); 
    if (mHelper != null) mHelper.dispose(); 
    mHelper = null; 
} 

난 그냥 사소한 문제라도, 그러나 어떤 아이디어/솔루션이 크게 감사합니다 내려다 보이는 해요 경우 확실하지!

그리고 실제로 폴더의 유틸리티 파일을 모두 9와 함께 올바른 자리에 IInAppBillingService.aidl을 추가 한 (Base64로, Secruity, SkuDeatils 요법 ...)

답변

0

어떤 이유로 android.test.purchased 경우 그것이 예정되어있을 때 소모되지 않습니다. consumeItem();을 추가하십시오. 에서 if (result.isFailure())를 호출하고, 앱을 실행하고, 구매 흐름을 다시 시작한 다음 충돌하고 android.test.purchased를 소비 한 다음 코드로 돌아가서 consumeItem()을 제거합니다. if (result.isFailure()) 내에서 호출하십시오. 다시 앱을 다시 실행하면 android.test.purchased를 다시 사용할 수있게됩니다.

관련 문제