首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android :设备上不可用的计费服务

Android :设备上不可用的计费服务
EN

Stack Overflow用户
提问于 2016-03-11 18:55:35
回答 2查看 3K关注 0票数 2

我正在尝试在我的应用程序中实现IAB。每次应用程序启动时,启动都会失败,原因如下:

Problem setting up In-app Billing: IabResult: Billing service unavailable on device. (response: 3:Billing Unavailable)

我什么都试过了:

  • 确保我在清单中拥有com.android.vending.BILLING权限。
  • 将APK上传到beta通道,这两个版本都对应。
  • 使用测试帐户。
  • 清除Google缓存。
  • 确保我的build.gradle中有最新的Google服务。
  • 再次检查公开编码的密钥。
  • 使用多个设备。

但无论如何,错误仍然存在。我读过所有关于它的问题和答案,但我不知道我错过了什么!

这是我的相关代码:

代码语言:javascript
运行
复制
 public class MainActivity extends AppCompatActivity {

    IabHelper       mHelper; 

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHelper = new IabHelper(this, Billing.ENCODED_PUBLIC_KEY);
        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (!result.isSuccess()) {
                    // Oh noes, there was a problem.
                    Log.d("LOG", "Problem setting up In-app Billing: " + result);
                }
                // Hooray, IAB is fully set up!
            }
        });
        final SharedPreferences saved_values = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        IabHelper.QueryInventoryFinishedListener mGotInventoryListener
                = new IabHelper.QueryInventoryFinishedListener() {
            public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
                if (result.isFailure()) {
                    SettingsActivity.premium = saved_values.getBoolean("premium",false);
                }
                else {
                    // does the user have the premium upgrade?
                    SettingsActivity.premium = inventory.hasPurchase(Billing.SKU_PREMIUM);
                    // update UI accordingly
                }
            }
        };
        try{
            mHelper.queryInventoryAsync(mGotInventoryListener);
        }
        catch (Exception e){
            SettingsActivity.premium = saved_values.getBoolean("premium",false);
        }
    }



    @Override public void onDestroy() {
        super.onDestroy();
       if (mHelper != null)
            mHelper.dispose();
        mHelper = null;
    }



    @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.i("LOG", "onActivityResult(" + requestCode + "," + resultCode + "," + data);

        // Pass on the activity result to the helper for handling
        if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
            super.onActivityResult(requestCode, resultCode, data);
        }
        else {
            Log.i("LOG", "onActivityResult handled by IABUtil.");
        }
    }

以下是控制台输出:

代码语言:javascript
运行
复制
03-11 20:35:27.896 710-710/? W/ActivityManager: Permission Denial: getCurrentUser() from pid=14441, uid=10189 requires android.permission.INTERACT_ACROSS_USERS
03-11 20:35:28.516 14441-14441/com.johan.app D/LOG: Problem setting up In-app Billing: IabResult: Billing service unavailable on device. (response: 3:Billing Unavailable)
03-11 20:35:28.516 14441-14441/com.johan.app E/IabHelper: In-app billing error: Illegal state for operation (queryInventory): IAB helper is not set up.

请注意,我有代码查询其他地方的库存,但是它没有超出mHelper.startUpSetup()的范围这一事实使它变得无关紧要。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-14 16:54:29

试试这个!只需转到IabHelper类,在onServiceConnected回调下的startSetup方法中。您可以看到一个意图,只需替换下面的代码。(或者只是查找BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE).

代码语言:javascript
运行
复制
 Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");
        if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
            // service available to handle that Intent
            mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
        }
        else {
            // no service available to handle that Intent
            if (listener != null) {
                listener.onIabSetupFinished(
                        new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                                "Billing service unavailable on device."));
            }
        }
票数 4
EN

Stack Overflow用户

发布于 2022-04-27 06:35:48

如果您的目标是android 31,请将其放在清单中:

代码语言:javascript
运行
复制
<permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<queries>
    <intent>
        <action android:name="android.intent.action.MAIN" />
    </intent>
</queries>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35947832

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档