2017-08-28 93 views
0

我想製作一款應用內購買應用。我有一個code.And我有谷歌播放控制檯所有設置。但id不起作用。它給了我這個錯誤: 「IabResult:錯誤檢查計費v3的支持。(響應:3:計費不可用)」 所以我想檢查我的設備是否支持應用內結算v3。這裏是我的代碼:如何檢查設備是否支持應用內結算v3 android

package com.khabuko.dtv; 

import android.content.Intent; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 

import com.khabuko.dtv.util.IabHelper; 
import com.khabuko.dtv.util.IabResult; 
import com.khabuko.dtv.util.Inventory; 
import com.khabuko.dtv.util.Purchase; 

public class InAppBillingActivity extends AppCompatActivity { 

private static final String TAG = 
     "InAppBilling"; 
IabHelper mHelper; 
static final String ITEM_SKU = "com.khabuko.item"; 

private Button clickButton; 
private Button buyButton; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_in_app_billing); 

    buyButton = (Button)findViewById(R.id.buyButton); 
    buyButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      buyClick(v); 
     } 
    }); 
    clickButton = (Button)findViewById(R.id.clickButton); 
    clickButton.setEnabled(false); 
    String base64EncodedPublicKey = 
      "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn+naZOOOHNVdP0zQMkeX5mFwBb9BU78cg4oqAxtY8gaMMuEHAaHBwU7yXW6zVh9uTof23SO4GzxTJcIPXCeTyMFmcoFkNvPtqZSFqYcqA5M8Ief0tzpXr81aLEe0lxSy/t3VTN29UA+AaXjt3bvsDXQQPUQXr1HEONfix6TsudI6SCILftZTMIfRZYfOU+0OJdi7J8uDkU2TBjz40UhGc4SWmCoANXVM5yjZ8w4jspXXmej7pP52NMb5nAlK5NrAgIEjHhSDrf8Sl0DhNwLTJM7e2yOWOPt/MvdDsQo1ensm2sSH0jwn1K04RVC8AIGPqtzxLZgP+Ysby0HKpMSU3wIDAQAB"; 

    mHelper = new IabHelper(this, base64EncodedPublicKey); 

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

public void buttonClicked (View view) 
{ 
    clickButton.setEnabled(false); 
    buyButton.setEnabled(true); 
} 

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

@Override 
protected void onActivityResult(int requestCode, int resultCode, 
           Intent data) 
{ 
    Log.i(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data); 
    if (!mHelper.handleActivityResult(requestCode, 
      resultCode, data)) { 
     super.onActivityResult(requestCode, resultCode, data); 
    }else { 
     Log.i(TAG, "onActivityResult handled by IABUtil."); 
    } 
} 

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(); 
      buyButton.setEnabled(false); 
     } 

    } 
}; 
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); 
       } else { 
        // handle error 
       } 
      } 
     }; 

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


} 

回答

0

IabHelper.OnIabSetupFinishedListener()中檢查應用內結算可用性。

但是你必須等待一段時間後創建新的SKU。 Google控制檯中的任何修改都不會立即發生。

+0

謝謝。但我已經知道了。現在我可以問你另一個問題嗎?無論如何,問題是如何獲得每個購買的收據並將其發送到服務器? – GreeDy6691

+0

最好問一個新問題,查看https://developer.android.com/google/play/billing/billing_reference.html#getPurchases –

+0

是的,它更好,但我沒有權限提出另一個問題。無論如何,我解決了這個問題謝謝你的關注:D – GreeDy6691

相關問題