1

私はこれに一週間以上苦労しています。私はAndroidでサブスクリプションに取り組んでおり、アプリ内課金バージョン3を使用しています。コードを作成して購入用に実行していますが、昨年行われたように、このバージョンはサブスクリプションをサポートしていませんでした。サブスクリプションを使用するためのコードをビルドするためのコードがありません。

これが私が購入のために用意しているコードです。私が理解しているように、購入ではなくサブスクリプションで機能するようにこれらを変更し、サブスクリプションがgoogleサーバーで有効かどうかを判断するためのコードを追加する必要があります。現在、そのためのコードは表示されていません。

    String base64EncodedPublicKey = "MI...QAB";
    mHelper = new IabHelper(this, base64EncodedPublicKey);

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

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                // complain("1 "+"Problem setting up in-app billing: " +
                // result);
                return;
            }
            mHelper.queryInventoryAsync(mGotInventoryListener);
        }
    });



// Listener that's called when we finish querying the items we own
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result,
            Inventory inventory) {
        // ///Log.d(TAG, "Query inventory finished.");
        if (result.isFailure()) {
            // complain("2 "+"Failed to query inventory: " + result);
            return;
        }
        // ///Log.d(TAG, "Query inventory was successful.");
        // place code here to proceess purchase without reaccessing database
        if (inventory.hasPurchase(appSKU)) {
            // ///Log.i("Purchase","purchase consumed here");

        //mHelper.consumeAsync(inventory.getPurchase(appSKU),mConsumeFinishedListener);

            return;
        }
    }
};

public void order(String appSKU) {
    mHelper.launchPurchaseFlow(this, appSKU, RC_REQUEST,
            mPurchaseFinishedListener);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + ","
    // + data);

    // Pass on the activity result to the helper for handling
    if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
        // not handled, so handle it ourselves (here's where you'd
        // perform any handling of activity results not related to in-app
        // billing...
        super.onActivityResult(requestCode, resultCode, data);
    } else {
        // ///Log.d(TAG, "onActivityResult handled by IABUtil.");
    }
}

// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
        // ///Log.d(TAG, "Purchase finished: " + result + ", purchase: " +
        // purchase);


        if(purchase == null) {
            ;
        }else {
        String tester1 = purchase.toString();

        // ///Log.d(TAG, "Purchase successful.");
    //  mHelper.consumeAsync(purchase, mConsumeFinishedListener);



           // myCallServer(udid, calltype, data, OrderID, ProductId, PurchaseToken) {


        Bundle myBundle = new Bundle();
        myBundle.putString("AppTitle", AppTitle);

        Intent myIntent = new Intent(getBaseContext(),
                IntroALevActivity.class);
        myIntent.putExtras(myBundle);
        startActivity(myIntent);
    }

    }

};

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

        // We know this is the "gas" sku because it's the only one we
        // consume,
        // so we don't check which sku was consumed. If you have more than
        // one
        // sku, you probably should check...
        if (result.isSuccess()) {
            // successfully consumed, so we apply the effects of the item in
            // our
            // game world's logic, which in our case means filling the gas
            // tank a bit
            alert("You made a purchase");
        } else {
                    ;
        }
    }
};

オンラインで調べましたが、既存のサブスクリプションをチェックするための正確なメソッドコードを決定するのに役立つ、壊れたコードしか見つかりませんでした。誰かが私のコードを見て、私が見逃しているメソッドを提供できれば、それは素晴らしいことです。Googleの例は通常は優れていますが、2月15日の時点でサブスクリプションがV3に追加されたばかりなので、構築するコーディング例は多くありません。

私は苦労しているので、質問がある場合や追加情報が必要な場合は、私に知らせてください。私はそれを提供するために最善を尽くします。

stackoverflowメンバーに感謝します

4

2 に答える 2

1

アプリのサブスクリプションで作業するには、作成した IabHelper インスタンスで「launchSubscriptionPurchaseFlow()」メソッドを呼び出す必要があると思います。

    mHelper.launchSubscriptionPurchaseFlow(Activity act, String sku, int requestCode,
    OnIabPurchaseFinishedListener listener, String extraData);

また

    mHelper.launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode,
                    OnIabPurchaseFinishedListener listener, String extraData);

itemType = IabHelper.ITEM_TYPE_SUBS

于 2014-01-10T09:03:38.170 に答える
1

私の実装ではサブスクリプションを使用していませんが、IabHelper.QueryInventoryFinishedListener mGotInventoryListener 関数で確認できます。したがって、これの代わりに:

// ///Log.d(TAG, "Query inventory was successful.");
    // place code here to proceess purchase without reaccessing database
    if (inventory.hasPurchase(appSKU)) {
        // ///Log.i("Purchase","purchase consumed here");

    //mHelper.consumeAsync(inventory.getPurchase(appSKU),mConsumeFinishedListener);

        return;
    }

これを使って:

Purchase haspurchase = inventory.getPurchase(appSKU);
if (haspurchase = null) {
    // do something since there wasn't a purchase
}
else {
   // do something if you have the purchase 
}
于 2013-03-18T07:02:29.063 に答える