如何启动inapp结算活动

时间:2012-08-09 10:10:45

标签: android android-layout in-app-purchase android-activity

我从互联网获取了一个用于inapp计费的代码,我想在我的应用程序中使用该代码但是我收到一个错误,当我点击我的应用程序的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();
}
   }

但现在我希望从案例R.id.gtask_button:我应该开始我从R.id.main_purchase_yes开始的应用内结算活动。

提前thnx ......

1 个答案:

答案 0 :(得分: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);