Android IAB:设备上无法使用结算服务 [英] Android IAB: Billing service unavailable on device

查看:2762
本文介绍了Android IAB:设备上无法使用结算服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用中实施IAB。每次应用程序启动时,启动都会失败,并显示:

I am trying to implement IAB in my app. Each time the app starts, the start up fails with:

设置应用程序内结算时出现问题:IabResult:设备上的结算服务不可用。 (回复:3:结算不可用)

我已经尝试了所有的一切:

I've tried literally everything:


  • 确保清单中有 com.android.vending.BILLING 权限。

  • 上传两个版本对应的APK到测试版渠道。

  • 使用测试帐户。

  • 清除Google Play缓存。

  • 确保我的 build.gradle 中有最新的Google Play服务。

  • 仔细检查公共编码密钥。

  • 使用多个设备。

  • Ensuring I have the com.android.vending.BILLING permission in the manifest.
  • Uploading the APK to the beta channel with both versions corresponding.
  • Using test accounts.
  • Clearing the Google Play cache.
  • Making sure I have the latest Google Play services in my build.gradle.
  • Double-checking the public encoded key.
  • Using multiple devices.

但无论如何,错误仍然存​​在。我已经阅读了所有SO问题&关于它的答案,但我无法弄清楚我错过了什么!

But no matter what, the error still persists. I've read all the SO questions & answers about it but I can't figure out what am I missing!

这是我的相关代码:

 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.");
        }
    }

这是控制台输出:

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()使其无关紧要。

Note that I have code querying the inventory somewhere else, but the fact that it doesn't go beyond mHelper.startUpSetup() makes it irrelevant.

推荐答案

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

Try this ! Just go to IabHelper class, in startSetup method under onServiceConnected callback. you can see a Intent, Just replace with below code. (or just Find for BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE).

 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."));
            }
        }

这篇关于Android IAB:设备上无法使用结算服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆