unity使用原生android方式接入google结算库5.0.0

接入Google IAP 使用billing 5.0.0版本时响应 FEATURE_NOT_SUPPORT
void OnRequstProduct(String[] productId) {

        List skuList = new ArrayList<>();
        skuList.addAll(Arrays.asList(productId));
        cacheRequestList=productId;
        QueryProductDetailsParams params = QueryProductDetailsParams.newBuilder()
            .setProductList(
                    ImmutableList.of(
                    QueryProductDetailsParams.Product.newBuilder()
                            .setProductId("")
                            .setProductType(BillingClient.ProductType.INAPP)
                            .build())
            ).build();
        if(billingClient == null) {
            ShowMessage("BillingClient is NULL!!!");
            return;
        }
        ShowMessage("RequestProduct01");
        BillingResult result = billingClient.isFeatureSupported(BillingClient.FeatureType.PRODUCT_DETAILS);
        if(result.getResponseCode() == BillingClient.BillingResponseCode.OK){
            billingClient.queryProductDetailsAsync(params,
                    new ProductDetailsResponseListener() {
                        @Override
                        public void onProductDetailsResponse(@NonNull BillingResult billingResult, @NonNull List list) {
                            ShowMessage("RequestProduct02");

                            int responseCode = billingResult.getResponseCode();
                            ShowMessage("onSkuDetailsResponse:"+billingResult+" code:"+GetResponseText(responseCode));
                            ShowMessage("RequestProduct03");
                            switch (responseCode){
                                case BillingClient.BillingResponseCode.OK:
                                    ShowMessage("RequestProduct04");
                                    RecieveProducts(list);
                                    break;
                                default:
                                    ShowMessage("RequestProduct05");
                                    RequestProductsFail("Failed to query inventory: " + billingResult.getDebugMessage());
                                    ShowMessage("Failed to query inventory: "+billingResult.getDebugMessage());
                                    break;
                            }
                            ShowMessage("RequestProduct06");
                        }
                    });
        }else{
            ShowMessage("Please update your Google Play Store and try again \nCode: " + GetResponseText(result.getResponseCode()));
        }

首先,你需要在 Unity 中导入 Google Play Services for Unity 插件。这个插件可以在 Unity Asset Store 中下载,并且可以帮助你在 Unity 中访问 Google Play 服务。

然后,你需要在 Unity 中创建一个 Android 项目。在这个项目中,你可以使用 Android Studio 或者其他 Android 开发工具来接入 Google 结算库。

具体来说,你需要在你的 Android 项目的 build.gradle 文件中添加依赖:

Copy code
dependencies {
    implementation 'com.android.billingclient:billing:5.0.0'
}

然后,你需要在你的 Android 项目中添加一个 BillingClient 对象,并使用它来进行订阅和内购交易。具体的实现细节可以参考 Google 的官方文档:

https://developer.android.com/google/play/billing/billing_library_overview

看错误好像是手机应用商店问题,看看应用商店更新到最新版本试试。

一般报错提示,找到谷歌文档查看具体信息即可。


当前设备上的 Play 商店不支持请求的功能。

如果您的应用想要在尝试使用该功能之前检查是否支持该功能,您的应用可以调用该功能BillingClient.isFeatureSupported(String)来检查该功能是否受支持。有关可以支持的功能类型的列表,请参阅BillingClient.FeatureType。

例如:调用API前, BillingClient.showInAppMessages(Activity, InAppMessageParams, InAppMessageResponseListener)可以调用featureType判断是否支持。 BillingClient.isFeatureSupported(String)BillingClient.FeatureType.IN_APP_MESSAGING

对了,FEATURE_NOT_SUPPORTED的错误代码后还有一个Debug message:

Client does not support ProductDetails

我认为这个调试信息同样意味着要升级PlayStore