2012-08-09 30 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

相关问题