簡體   English   中英

應用內結算(購買),將應用與項目關聯

[英]In app billing(purchase) linking app with items

我正在嘗試在應用中添加應用購物/計費功能,因此當用戶購買商品時,我會刪除廣告。 我有使用SKU = "android.test.purchased"示例代碼。 現在,我的問題是如何將應用程序鏈接到我的物品-我在一個小時前上傳了啟用結算功能的新apk,創建並發布了該物品,但是當我嘗試購買該物品時,我得到了: 在此處輸入圖片說明

這是我的代碼:

public class RemoveAds extends AthanBaseActivity implements OnClickListener {

    private static final String TAG = "inappbilling";
    IabHelper mHelper;
    //ID from playstore 16xxxx15_removeads.
//android.test.purchased
    static final String ITEM_SKU = "com.myapppackage.16xxxx15_removeads.";

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.remove_ads);

        findViewById( R.id.remove_ads_).setOnClickListener(this);

        setupInAppPurchase();

    }

    public void consumeItem() {
        mHelper.queryInventoryAsync(mReceivedInventoryListener);
    }

    IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result,
                Inventory inventory) {

            if (result.isFailure()) {
                // Handle failure
            } else {
                mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
                        mConsumeFinishedListener);
            }
        }
    };

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mHelper != null)
            mHelper.dispose();
        mHelper = null;
    }

    IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
        public void onConsumeFinished(Purchase purchase, IabResult result) {

            if (result.isSuccess()) {
                Toast.makeText(RemoveAds.this, "SUCCESS", Toast.LENGTH_LONG)
                        .show();
            } else {
                Toast.makeText(RemoveAds.this, "ERROR purchase",
                        Toast.LENGTH_LONG).show();
                // handle error
            }
        }
    };

    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
            if (result.isFailure()) {
                // Handle error
                return;
            } else if (purchase.getSku().equals(ITEM_SKU)) {
                consumeItem();
                // buyButton.setEnabled(false);
            }

        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

    private void setupInAppPurchase() {
        String base64EncodedPublicKey = "MIIBIjANBgkqhkcccxxxxxdomr somelongstringdfsdfsdfsfsdofksdofkdsMXz0R4EJuw7YZkQ8jMPemymSbQGtLllH+fu85hfQIDAQAB";

        mHelper = new IabHelper(this, base64EncodedPublicKey);

        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (!result.isSuccess()) {
                    Log.d(TAG, "In-app Billing setup failed: " + result);
                } else {
                    Log.d(TAG, "In-app Billing is set up OK");
                }
            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.remove_ads_:
            mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001,
                    mPurchaseFinishedListener, "mypurchasetoken");
            break;
        }

    }

}

如果您實際的android設備上的主要帳戶與開發者帳戶相同,則您將無法進行購買。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM