0

我从互联网上获得了一个用于应用内计费的代码,我想在我的应用程序中使用该代码,但我收到一个错误,当我单击 我buy button的应用程序layoutButton点击我的应用内结算开始。

我希望当我点击我的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提前...

4

1 回答 1

0

From what i see, this is called when you click the button

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

So maybe thats where it changes your layout to something else...

Post the method so we can take a look.

EDIT:

Ok, here's the code

 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());
            }
    }

and we find the culprit -

 startBuyPageActivity(pendingIntent, new Intent(), activityContext);
于 2012-08-09T10:21:47.867 回答