简体   繁体   中英

Google Play In-App Billing: Test purchase does not work + No product details available

I am trying to add Googles In-App Billing to my Android 4+ app. I have set up everything as described in " Preparing Your In-app Billing Application ". Now I have uploaded the app to the Alpha testing channel in the Developer console.

Additionally I have set up a test account ( described here ) to be able purchase the items without triggering a real payment.

After installing the alpha version from the Play Store on my test device (using the test account of course) there a two problems:

  1. No product information is fetched from the Play Store. Thus I cannot show any price information, etc.

  2. When I start a purchase there is absolutly no hint, that this will be a free test purchase. Everything looks exactly like a real purchase.

This is the code I use:

String publicKey = MyApp.getPublicKey(); // de-code and get the public key
final IabHelper googlePlayHelper = new IabHelper(context, publicKey);

Log.d("TAG", "IabHelber Init");

googlePlayHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
    public void onIabSetupFinished(IabResult result) {
        if (!result.isSuccess()) {
            Log.d("TAG", "IabHelber Init - Non Success: " + result);
        } else {
            Log.d("TAG", "IabHelber Init - SUCCESS");
            try {
                googlePlayHelper.queryInventoryAsync(true, new IabHelper.QueryInventoryFinishedListener() {
                    public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
                        if (result.isFailure()) {
                            Log.d("TAG", "query Inventory - Non Success: " + result);
                        } else {
                            Log.d("TAG", "query Inventory - SUCCESS");

                            if (inventory.hasDetails(2my.product.id")) {
                                Log.d("TAG", "NO DETAILS");
                            } else {
                                Log.d("TAG", "Has Details");
                            }
                        }
                    }
                }      
            } catch (Exception e) { 
                Log.d("TAG", "EXCEPTION: " + e.getMessage());
            }
        }
    }
});

The Log shows the following:

D/TAG (25995): IabHelber Init
D/TAG (25995): IabHelber Init - SUCCESS
D/TAG (25995): query Inventory - SUCCESS
D/TAG (25995): NO DETAILS

What could be the reason that now details are fetched? The docs that that there should be an hint when performing a test purchase. Why am I runnig a "real" purchase instead?

I have not been able to find out why purchases by test users are not handled as test purchases. But the problem with the missing product details is solved:

I used the following call to query the inventory:

googlePlayHelper.queryInventoryAsync(true, new IabHelper.QueryInventoryFinishedListener() { ... });

This is totally valid code and the first parameters (true in this example) states, that the query should fetch the product details. But it seems, that this parameter does not have any effect until a further parameter is given: One has to explicitly specify the IDs of the product one would like to fetch:

List<String> productIDs = new ArrayList<String>();
productIDs.add(IAP_ID_1);
productIDs.add(IAP_ID_2);
productIDs.add(IAP_ID_3); 

googlePlayHelper.queryInventoryAsync(true, productIDs, new IabHelper.QueryInventoryFinishedListener() { ... });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM