Wednesday, August 29, 2012

購買in-app billing,Google Play視窗開了2次

今天遇到一件事,
至從增加Subscription服務後,
Dungeons在request購買時,
畫面會先跳出找不到項目,
然後又跳出in-app billing商品列表,
I encountered a problem when I was using Google In-app billing today that is when I request purchase, Google Play Billiing view shows twice.
First, It shown "Can't find Item" dialog then shown me the in-app billing product item what I set.

爬文才發現問題出在Google Play Billing的Sample Code:Dungeons.java出了一個邏輯上的錯誤,
那就是︰
Finally I figure out the cause is logic in in-app billing sample code:Dungeons.java.
Wrong code is on below:


 @Override
    public void onClick(View v) {
        if (v == mBuyButton) {
            if (Consts.DEBUG) {
                Log.d(TAG, "buying: " + mItemName + " sku: " + mSku);
            }

            if (mManagedType != Managed.SUBSCRIPTION &&
                    !mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_INAPP, mPayloadContents)) {
                showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
            } else if (!mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_SUBSCRIPTION, mPayloadContents)) {
                // Note: mManagedType == Managed.SUBSCRIPTION
                showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
            }

        } else if (v == mEditPayloadButton) {
            showPayloadEditDialog();
        } else if (v == mEditSubscriptionsButton) {
            editSubscriptions();
        }
    }

紅色那段的邏輯錯誤,
造成Google Play視窗被開啟兩次,
只要將那段改成
 if (mManagedType != Managed.SUBSCRIPTION &&
                    !mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_INAPP, mPayloadContents)) {
                showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
            } else if (mManagedType == Managed.SUBSCRIPTION && !mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_SUBSCRIPTION, mPayloadContents)) {
                // Note: mManagedType == Managed.SUBSCRIPTION
                showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
            }
即可改善Billing視窗開了2次的問題。 
If modify code as above will fix this bug.

Friday, August 10, 2012

輸出時出現Dalvik的UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException

今天將isLibrary的專案Build出來時,
遇到一個
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/xxx/sample/R$attr;
的錯誤,
結果在Library裡將bin目錄底下的com/xxx/sample/刪掉,
就能正常Build出程式了。