好的,在這裏我的GUI是suppossed更新時,購買完成。我正在使用android.test.purchase和GUI不更新,我應該擔心或不?購買inApp賬單後GUI沒有更新更新android
變量
IabHelper mHelper;
static final String TAG = "com.back.to.school.zone.readingLevelPicker";
// SKUs for our products: the premium upgrade (non-consumable)
static final String SKU_PREMIUM = "android.test.refunded";
// Does the user have the premium upgrade?
boolean mIsPremium = false;
// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 20;
onCreate方法
String base64EncodedPublicKey = "<my key is in here>";
mHelper = new IabHelper(this, base64EncodedPublicKey);
//It is recommended to add more security than just pasting it in your source code;
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if (!result.isSuccess()) {
// Oh noes, there was a problem.
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
一個按鈕來購買需要的物品
buyButton = (Button) findViewById(R.id.buyButtonS);
buyButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mHelper.launchPurchaseFlow(readingLevelPicker.this, SKU_PREMIUM, 10001,
mPurchaseFinishedListener, "");
}
一個需要的按鈕啓用和的結束mLevel10
mLevel10.setEnabled(false);
mLevel10.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(),
readingMode10.class); // Coming soon
startActivityForResult(myIntent, 0);
}
});
} //end of oncreate method
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
if (result.isFailure()) {
Log.d(TAG, "Failed to query inventory: " + result);
return;
}
else {
Log.d(TAG, "Query inventory was successful.");
// does the user have the premium upgrade?
mIsPremium = inventory.hasPurchase(SKU_PREMIUM);
// update UI accordingly
mLevel6 = (Button) findViewById(R.id.level6);
mLevel7 = (Button) findViewById(R.id.level7);
mLevel8 = (Button) findViewById(R.id.level8);
mLevel9 = (Button) findViewById(R.id.level9);
mLevel10 = (Button) findViewById(R.id.level10);
mLevel6.setEnabled(true);
mLevel7.setEnabled(true);
mLevel8.setEnabled(true);
mLevel9.setEnabled(true);
mLevel10.setEnabled(true);
Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
}
Log.d(TAG, "Initial inventory query finished; enabling main UI.");
}
};
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
return;
}
else if (purchase.getSku().equals(SKU_PREMIUM)) {
// give user access to premium content and update the UI
mLevel6 = (Button) findViewById(R.id.level6);
mLevel7 = (Button) findViewById(R.id.level7);
mLevel8 = (Button) findViewById(R.id.level8);
mLevel9 = (Button) findViewById(R.id.level9);
mLevel10 = (Button) findViewById(R.id.level10);
mLevel6.setEnabled(true);
mLevel7.setEnabled(true);
mLevel8.setEnabled(true);
mLevel9.setEnabled(true);
mLevel10.setEnabled(true);
}
}
};
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + ","
+ data);
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
} else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
一些意見後創建方法 - 從我瞭解一切工作儘可能的計費方式使用機器人時,因爲去。測試。購買它說支付完成。但用戶界面不啓用文本框,因此使文本框被禁用,我嘗試在位置mLevel7.setEnabled(「true」)處拋出一個斷點,但它不顯示任何不尋常的東西,沒有任何失敗提供了UI沒有更新?爲什麼?
請在onCreate()方法mLevel6,7,8,9,10中定義您的按鈕變量。只有setEnable()方法的代碼應該位於onInventoryFinish或onIabPurchaseFinished Listener中。並且在onCreate()中將所有按鈕設置爲禁用。 – Maulik