如何修复 Android 应用的应用购买问题?

Posted

技术标签:

【中文标题】如何修复 Android 应用的应用购买问题?【英文标题】:How to fix in app purchase for android app? 【发布时间】:2021-10-03 06:21:27 【问题描述】:

我在 google play 商店中有一个应用程序,在添加计费 3V 来处理订阅时遇到了一些问题。 付款后任何新订阅者都无法在我的应用程序中访问,并且付款完成并出现在谷歌控制台中。

我希望能帮助我在我的应用程序中处理应用内购买,这是代码:

public static void isUserHasSubscription(Context context, onCheck onCheck) BillingClient billingClient = BillingClient.newBuilder(context).enablePendingPurchases().setListener(new PurchasesUpdatedListener() @覆盖 public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List list)

        
    ).build();

    billingClient.startConnection(new BillingClientStateListener() 
        @Override
        public void onBillingSetupFinished(BillingResult billingResult) 
            Purchase.PurchasesResult purchasesResult=billingClient.queryPurchases(BillingClient.SkuType.SUBS);


            billingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.SUBS,(billingResult1, list) -> 

                Log.d("billingprocess","purchasesResult.getPurchasesList():"+purchasesResult.getPurchasesList());

                //                        //here you can pass the user to use the app because he has an active subscription
                //                        Intent myIntent=new Intent(context,MainActivity.class);
                //                        startActivity(myIntent);
                boolean isPrshees = billingResult1.getResponseCode() == BillingClient.BillingResponseCode.OK && !Objects.requireNonNull(purchasesResult.getPurchasesList()).isEmpty();

                onCheck.onCheck(isPrshees,isPrshees?getOrderId(purchasesResult.getPurchasesList().get(0).getOriginalJson()):"");

            );
        
        @Override
        public void onBillingServiceDisconnected() 
            onCheck.onCheck(false,"") ;
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
            Log.d("billingprocess","onBillingServiceDisconnected");
        
    );

【问题讨论】:

【参考方案1】:

我使用了下面的库,它工作正常。 请尝试一下,希望对您有所帮助。 https://github.com/anjlab/android-inapp-billing-v3 谢谢。

【讨论】:

非常感谢,我会试试你的计划。【参考方案2】:

Android In-App Billing API 的简单实现。

dependencies 
    implementation 'com.github.moisoni97:google-inapp-billing:1.0.5'

更多信息。在 Github 上:- https://github.com/Mahadev-code/Android-inApp-Billing

【讨论】:

虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。

以上是关于如何修复 Android 应用的应用购买问题?的主要内容,如果未能解决你的问题,请参考以下文章

如何从 Android Google Play 中删除测试 IAP 购买

如何从Android Google Play中删除测试IAP购买

如何修复应用内购买错误“交易错误:无法连接到 iTunes Store 代码 0”? [复制]

如何在android中确认应用内购买?

如何从付费应用转换为应用内购买? iOS 和 Android + Flutter

Android 应用内购买订阅并免费试用 - 如何避免滥用?