IabHelper launchPurchaseFlow google play In-app Billing找不到产品

时间:2014-10-17 09:26:50

标签: java android

  • 我下载了示例应用
  • 从开发者控制台获取我的密钥
  • 在我的清单中添加适当的权限

没有任何帮助:我总是找不到产品...... Thanx - 拉尔夫

这是代码,Java,Android Studio     //用户是否有专业升级?应该是应用程序内产品

private static Boolean _PROFESSIONAL = false;

// Debug tag, for logging
private static final String TAG_BILLING = "BillingService";

// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 10001; // 10002 does not help either...

// The helper object
IabHelper mHelper = null;

static final String SKU_PROFESSIONAL = "com...";

private String base64EncodedPublicKey = "KSRWbpF........... from Google play Developer Console

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // Create the helper, passing it our context and the public key to verify signatures with
    mHelper = new IabHelper(this, base64EncodedPublicKey);

    // enable debug logging (for a production application, you should set this to false).
    mHelper.enableDebugLogging(true);

    // Start setup. This is asynchronous and the specified listener
    // will be called once setup completes.
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        @Override
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh no, there was a problem.
                return;
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null) return;

            // IAB is fully set up. Now, let's get an inventory of stuff we own.
            mHelper.queryInventoryAsync(true, null, mGotInventoryListener);
        }
    });
}

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
        Log.d(TAG_BILLING, "Query inventory finished.");

        // Have we been disposed of in the meantime? If so, quit.
        if (mHelper == null) return;

        // Is it a failure?
        if (result.isFailure()) {
            complain("Failed to query inventory: " + result);
            return;
        }

        // Do we have the premium upgrade?
        Purchase premiumPurchase = inventory.getPurchase(SKU_PROFESSIONAL);
        _PROFESSIONAL = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
    }
};

// User clicked the menu upgrade professional
private void Upgrade() {
    String payload = sMyPurchaseToken;

    // tested, but no help
    // define IabHelper.flagEndAsync() as public, and add iabHelper.flagEndAsync() before iabHelper.launchPurchaseFlow(...)
    // mHelper.flagEndAsync();

    // could be tested: this, "android.test.purchased", 10002

    /////////// here the program shows the Google Play message that the programm does not exist... or is not configured for payment...
    mHelper.launchPurchaseFlow(MyActivity.this, SKU_PROFESSIONAL, RC_REQUEST, mPurchaseFinishedListener, payload);

    //mHelper.launchPurchaseFlow(this, "android.test.purchased", 10002, is ok
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG_BILLING, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
    if (mHelper == null) return;

    // Pass on the activity result to the helper for handling
    if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
    }
    else {
    }
}

boolean verifyDeveloperPayload(Purchase p) {
    String payload = p.getDeveloperPayload();
    return true;
}

// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
        // if we were disposed of in the meantime, quit.
        if (mHelper == null) return;

        if (result.isFailure()) {
            complain("Error purchasing: " + result);
            setWaitScreen(false);
            return;
        }
        if (!verifyDeveloperPayload(purchase)) {
            complain("Error purchasing. Authenticity verification failed.");
            setWaitScreen(false);
            return;
        }

        if (purchase.getSku().equals(SKU_PROFESSIONAL)) {
            _PROFESSIONAL = true;
        }
    }
};

// Called when consumption is complete
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
    public void onConsumeFinished(Purchase purchase, IabResult result) {
        Log.d(TAG_BILLING, "Consumption finished. Purchase: " + purchase + ", result: " + result);

        // if we were disposed of in the meantime, quit.
        if (mHelper == null) return;

        if (result.isSuccess()) {
        }
        else {
            complain("Error while consuming: " + result);
        }
    }
};

0 个答案:

没有答案