Android inapp结算responseList为空

Goo*_*oey 18 android skus in-app-billing

我在我的应用程序中定义了一些应用程序产品.我已将apk上传到Google Play,并在Google Play上添加了inapp购买产品.

我的ServiceConnection定义如下:

ServiceConnection mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mService = IInAppBillingService.Stub.asInterface(service);
            connect();
        }
    };
Run Code Online (Sandbox Code Playgroud)

onServiceConnected调用该函数,bindService返回true.

接下来是connect功能.

public void connect() {
        new Thread(new Runnable() {
            public void run() {
                try {

                    // Purchase type is "inapp", as required by  API v3
                    Bundle skuDetails = mService.getSkuDetails(3, PACKET, "inapp", querySkus);

                    }

                    int response = skuDetails.getInt("RESPONSE_CODE");

                    Log.e("IAP connect", response + "");


                    if (response == 0) {
                        ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
                        Log.e("size list", responseList.size()+"");
                        ...
                      }
                    }
            } catch (RemoteException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Run Code Online (Sandbox Code Playgroud)

这里的PACKET设置为getPackageName().响应代码为0,但是日志打印出列表的大小为0.我不知道为什么列表为空,因为我已经为Google Play输入了5个项目,并且每个项目都是活动的.我已经等了2天,用三台设备进行了测试,但仍然没有项目通过.

我几乎尝试了所有我能想到的东西,所以欢迎任何建议.

kup*_*sef 30

您需要应用程序发布到Beta/Alpha才能访问inapp计费功能.它最近有所改变,但他们没有宣布它:)

http://developer.android.com/google/play/billing/billing_testing.html#draft_apps

值得一提的是,您无需上传每个新版本以便能够对其进行测试.只需使用相同的versionCode和versionName,如果应用程序已发布,它将起作用.

  • 您确实必须发布您的应用程序 - 因为我发布的应用程序开始返回 skydetailslist。这是一个真正的美丽。你需要在 GooglePLay 中填写 App Store 信息并通过 Google 的审核才能测试应用内购买,在我看来,截至 2020 年 9 月 9 日,这是一个糟糕的设计,但事实就是如此。 (4认同)

小智 21

你的代码看起来不错.

确保查询正确的SKU.querySkus中的单个项目必须与应用内商品的ID完全匹配.

第二,确保查询项目的正确类型.如果您在开发者控制台中将"in app products"配置为要购买的汽车,请像使用"inapp"一样使用.如果您有订阅,请使用"subs"作为针对Google Play的查询类型.

希望这可以帮助.

  • 我不能赞成一百次,但我会!关于“subs”与“inapp”的那一点非常感谢! (3认同)