2012-08-09 36 views
0

我有一個代碼,從互聯網上的應用程式內計費和我想使用該代碼在我的應用程序,但我得到一個錯誤,當我點擊我的應用程序的的buy button重定向我到另一個layout的代碼,我得到另一個Button,然後點擊我的應用內結算開始。如何啓動一個應用程式內結算活動

我希望當我點擊我的buy button時,應用程序開票應該開始。沒有任何其他button點擊。

這是在應用內計費開始的代碼。

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    mSP = PreferenceManager.getDefaultSharedPreferences(this); 

    Log.i("BillingService", "Starting"); 
    setContentView(R.layout.contact_market); 

    mContext = this; 

    mPurchaseButton = (Button) findViewById(R.id.main_purchase_yes); 
    mPurchaseButton.setOnClickListener(this); 

    mPreview = (TextView) findViewById(R.id.chakkde); 

    startService(new Intent(mContext, BillingService.class)); 
    BillingHelper.setCompletedHandler(mTransactionHandler); 

} 

public Handler mTransactionHandler = new Handler() { 
    public void handleMessage(android.os.Message msg) { 
     Log.i(TAG, "Transaction complete"); 
     Log.i(TAG, "Transaction status: " 
       + BillingHelper.latestPurchase.purchaseState); 
     Log.i(TAG, "Item purchased is: " 
       + BillingHelper.latestPurchase.productId); 

     if (BillingHelper.latestPurchase.isPurchased()) { 
      showItem(); 
     } 
    }; 

}; 

@Override 
public void onClick(View v) { 
    switch (v.getId()) { 
    case R.id.main_purchase_yes: 
     if (BillingHelper.isBillingSupported()) { 
      BillingHelper.requestPurchase(mContext, 
        "android.test.purchased"); 
     } else { 
      Log.i(TAG, "Can't purchase on this device"); 
      mPurchaseButton.setEnabled(false); 
     } 

     break; 
    default: 

     Log.i(TAG, "default. ID: " + v.getId()); 
     break; 
    } 

} 

private void showItem() { 
    mPreview.setVisibility(View.VISIBLE); 
    SharedPreferences.Editor prefEditor = mSP.edit(); 
    prefEditor.putBoolean(DroidSugarPreference.KEY_ENABLE, 
      true); 
    prefEditor.commit(); 
    startActivity(new Intent(InAppMain.this, Setup.class)); 
    InAppMain.this.finish(); 
} 

@Override 
protected void onPause() { 
    Log.i(TAG, "onPause())"); 
    super.onPause(); 
} 

@Override 
protected void onDestroy() { 
    BillingHelper.stopService(); 
    super.onDestroy(); 
} 
    } 

這一點,如果從我所說的以上級

public void onClick(View v) { 
     // TODO Auto-generated method stub 
     switch (v.getId()) { 
     case R.id.gtask_button: 
      startActivity(new Intent(getActivity(), InAppMain.class)); 
     default: 
      break; 
     } 

,但現在我想從案例R.id.gtask_button:我應該開始,我從開始應用內結算活動R.id.main_purchase_yes。

事先日Thnx ...

回答

0

從我看到,當你點擊該按鈕

BillingHelper.requestPurchase(mContext, "android.test.purchased"); 

因此,也許這就是它改變了你的佈局到別的東西這就是所謂的...

發佈該方法,以便我們可以查看。

編輯:

好吧,這裏是代碼

protected static void requestPurchase(Context activityContext, String itemId){ 
      if (amIDead()) { 
        return; 
      } 
      Log.i(TAG, "requestPurchase()"); 
      Bundle request = makeRequestBundle("REQUEST_PURCHASE"); 
      request.putString("ITEM_ID", itemId); 
      try { 
        Bundle response = mService.sendBillingRequest(request); 

        //The RESPONSE_CODE key provides you with the status of the request 
        Integer responseCodeIndex  = (Integer) response.get("RESPONSE_CODE"); 
        //The PURCHASE_INTENT key provides you with a PendingIntent, which you can use to launch the checkout UI 
        PendingIntent pendingIntent = (PendingIntent) response.get("PURCHASE_INTENT"); 
        //The REQUEST_ID key provides you with a unique request identifier for the request 
        Long requestIndentifier   = (Long) response.get("REQUEST_ID"); 
        Log.i(TAG, "current request is:" + requestIndentifier); 
        C.ResponseCode responseCode = C.ResponseCode.valueOf(responseCodeIndex); 
        Log.i(TAG, "REQUEST_PURCHASE Sync Response code: "+responseCode.toString()); 

        startBuyPageActivity(pendingIntent, new Intent(), activityContext); 
      } catch (RemoteException e) { 
        Log.e(TAG, "Failed, internet error maybe", e); 
        Log.e(TAG, "Billing supported: "+isBillingSupported()); 
      } 
    } 

,我們找到了罪魁禍首 -

startBuyPageActivity(pendingIntent, new Intent(), activityContext); 
+0

我從這裏HTTP得到了應用內結算代碼://博客。 blundell-apps.com/simple-inapp-billing-payment/#comment-529 – Jpm 2012-08-09 10:25:25

+0

先生談到amIDead()返回從那裏而已。並顯示在日誌 – Jpm 2012-08-09 10:35:39

+0

「無法在此設備上購買」一切都正常運行,如上圖所示,當我從Inappmain.class開始。 – Jpm 2012-08-09 10:37:09

相關問題