簡體   English   中英

使用OpenIAB提交到Amazon Appstore

[英]Submitting to Amazon Appstore with OpenIAB

我們在購買應用程序的第一個Android應用程序中正在使用OpenIAB。 我們進行了所有設置,並能夠使用Amazon App Tester在設備上成功測試,並可以在終端中使用./adb install -i com.amazon.venezia appname.apk命令安裝應用程序。

但是,當我們提交到Amazon Appstore時,他們的測試人員拒絕了我們,因為該應用程序不會下載應用程序內購買/價格。 我應該評論一下,它在使用OpenIAB的Google Play中也能很好地工作。

我已經包含了我們在下面編寫的代碼。 我們還按照網站的建議設置了manifest和proguard-rules.pro。 任何幫助將不勝感激,因為我們在亞馬遜的支持下無濟於事:

public class InAppBilling {
private static final String TAG = "InAppBilling";
private static InAppBilling mInstance = null;

// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = <number goes here>;

private OpenIabHelper mHelper;
private NoteListFragment mFragment;
private Context mContext;

private InAppBilling() {}

public static InAppBilling get() {
    if (mInstance == null) {
        InAppConfig.init();
        mInstance = new InAppBilling();
    }
    return mInstance;
}

public OpenIabHelper getHelper() {
    return mHelper;
}

// Initialize OpenIAB library and when completed automatically kick off full product info download
public void init(Context context, NoteListFragment fragment) {
    mContext = context;

    // If library was already initialized, go straight to info download, don't init twice
    if (mHelper != null) {
        InAppBilling.get().queryPricesAndPurchases(fragment);
        return;
    }

    // Create the helper, passing it our context and the public keys to verify signatures with
    //Log.d(TAG, "Creating IAB helper.");
    OpenIabHelper.Options.Builder builder = new OpenIabHelper.Options.Builder()
            .setStoreSearchStrategy(OpenIabHelper.Options.SEARCH_STRATEGY_INSTALLER_THEN_BEST_FIT)
            .setVerifyMode(OpenIabHelper.Options.VERIFY_EVERYTHING)
            .addStoreKeys(InAppConfig.STORE_KEYS_MAP);
    mHelper = new OpenIabHelper(context, builder.build());

    // enable debug logging (for a production application, you should comment this out)
    //OpenIabHelper.enableDebugLogging(true);

    // Start setup. This is asynchronous and the embedded listener
    // will be called once setup completes.
    //Log.d(TAG, "Starting IAB setup.");
    mFragment = fragment;   // cache for use by callback
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            //Log.d(TAG, "IAB Setup finished.");

            if (!result.isSuccess()) {
                //Log.d(TAG, "Problem setting up in-app billing: " + result);
                mHelper = null;
                return;
            }

            //Log.d(TAG, "IAB Setup successful.");
            InAppBilling.get().queryPricesAndPurchases(null);   // use cached mFragment
        }
    });
}

// Launches a background download of info for all products
public void queryPricesAndPurchases(NoteListFragment fragment) {
    if (fragment != null)
        mFragment = fragment;
    //Log.d(TAG, "Launching product info query");
    mHelper.queryInventoryAsync(true, InAppConfig.ALL_SKUS, mGotInventoryListener);
}

// Listener that's called when we finish querying the product info
// Sets the price info for all packs, and clears and then re-sets the notes' purchased states
private IabHelper.QueryInventoryFinishedListener mGotInventoryListener =
        new IabHelper.QueryInventoryFinishedListener() {
            @Override
            public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
                //Log.d(TAG, "Query inventory finished: " + inventory.getAllPurchases() + inventory.getAllOwnedSkus());
                if (result.isFailure()) {
                    //Log.d(TAG, "Failed to query inventory: " + result);
                    return;
                }
                //Log.d(TAG, "Query inventory was successful.");

                // Note & pack data controller singletons already exist (created at startup)
                // so we don't need to pass a Context here (which we don't really have handy)
                PackDataController pdc = PackDataController.get(null);
                NoteDataController ndc = NoteDataController.get(null);
                ndc.returnAllNotes();

                for (String sku : InAppConfig.ALL_SKUS) {
                    Pack pack = pdc.findPackWithAppStoreId(sku);
                    if (pack != null) {
                        if (inventory.hasDetails(sku)) {
                            SkuDetails details = inventory.getSkuDetails(sku);
                            String price = details.getPrice();
                            pack.setPrice(price);   // supposedly localized according to user's account
                            //Log.d(TAG, "SKU " + sku + " = " + price);
                        } else {
                            //Log.d(TAG, "SKU " + sku + " details not found");
                        }

                        if (inventory.hasPurchase(sku)) {
                            Purchase purchase = inventory.getPurchase(sku);
                            if (verifyDeveloperPayload(purchase)) {
                                //Log.d(TAG, "Purchased SKU " + sku);
                                ndc.purchaseNotesWithPackId(pack.getId(), true);
                            } else {
                                //Log.d(TAG, "Payload verification failed SKU " + sku);
                            }
                        }
                    }
                }

                ndc.updateNoteList();
                mFragment.updateNoteAdapter();
            }
        };

/**
 * Verifies the developer payload of a purchase.
 */
boolean verifyDeveloperPayload(Purchase p) {
    String store = mHelper.getConnectedAppstoreName();
    if (store != null && store.equals(OpenIabHelper.NAME_AMAZON))
        return true;    // Amazon doesn't support payload verification, so bypass it
    if (p == null || p.getSku() == null)
        return false;
    String payload = p.getDeveloperPayload();
    if (payload == null)
        return false;

    return payload.equals(p.getSku() + p.getSku().length() * 13);
}

// Launches a product purchase request in a background thread
public void purchase(Activity act, String sku) {
    if (!sku.contains("."))
        sku = InAppConfig.SKU_PREFIX + sku;
    String payload = sku + sku.length() * 13;
    mHelper.launchPurchaseFlow(act, sku, RC_REQUEST, mPurchaseFinishedListener, payload);
}

// 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 (result.isFailure()) {
            //Log.d(TAG, "Error purchasing: " + result);
            return;
        }
        if (!verifyDeveloperPayload(purchase)) {
            //Log.d(TAG, "Error purchasing. Authenticity verification failed.");
            return;
        }

        //Log.d(TAG, "Purchase successful: " + purchase.getAppstoreName() + ", SKU: " + purchase.getSku());
        PackDataController pdc = PackDataController.get(null);
        Pack pack = pdc.findPackWithAppStoreId(purchase.getSku());
        NoteDataController ndc = NoteDataController.get(null);
        ndc.purchaseNotesWithPackId(pack.getId(), true);
        ndc.updateNoteList();
        if (mFragment != null)
            mFragment.updateNoteAdapter();

        Intent intent = new Intent("purchase-completed");
        // You can also include some extra data.
        intent.putExtra("message", "Purchase completed, reload template");
        LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
    }
};
}

您可能需要仔細檢查並確保已提交您的應用內購買商品,並且這些商品在Amazon Developer Console上處於活動狀態。

Amazon App Tester允許您在沙盒環境中進行測試。 根據我的經驗,它不能完全復制生產環境。 因此,即使您能夠使用App Tester成功進行測試,我仍建議您使用其Live App Testing服務在實際生產環境中進行測試

暫無
暫無

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

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