明小天 2022-12-23 18:04 采纳率: 25%
浏览 81

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

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

        List<String> 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<ProductDetails> 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()));
        }

  • 写回答

3条回答

  • 搞IT的小李 2022-12-24 00:14
    关注

    首先,你需要在 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

    评论

报告相同问题?

问题事件

  • 创建了问题 12月23日

悬赏问题

  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错