简体   繁体   English

Google Play许可 - 错误6是什么?

[英]Google Play License - what is error 6?

I am testing my app with the Google Play License API. 我正在使用Google Play许可API测试我的应用。 The app binds successfully to the licensing service, but the callback gives error 6. I've checked the error codes in LicenseValidator and this is not one of the error codes listed there. 该应用程序成功绑定到许可服务,但回调给出错误6.我已检查LicenseValidator中的错误代码,这不是其中列出的错误代码之一。

Does anyone know what error 6 means? 有谁知道错误6是什么意思?

public class MyActivity extends FragmentActivity
{

    private static final String BASE64_PUBLIC_KEY = "ZZZZ";

    private static final byte[] SALT = new byte[] {
        XXXX
    };

    private LicenseCheckerCallback mLicenseCheckerCallback;
    private LicenseChecker mChecker;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);

        String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

        // Library calls this when it's done.
        mLicenseCheckerCallback = new YAHLicenseCheckerCallback();

        // Construct the LicenseChecker with a policy, obfuscator and public key
        mChecker = new LicenseChecker(this, 
                new ServerManagedPolicy(this,
                new AESObfuscator(SALT, getPackageName(), deviceId)),
                BASE64_PUBLIC_KEY);
        mChecker.checkAccess(mLicenseCheckerCallback);
    }

    private class YAHLicenseCheckerCallback implements LicenseCheckerCallback {
        public void allow(int policyReason) {
            Log.d(tag,"License - allowed");

            if (isFinishing()) {
                // Don't do anything if Activity is finishing.
                return;
            }
            // Should allow user access.

        }

        public void dontAllow(int policyReason) {
            Log.d(tag,"License - not allowed");

            if (isFinishing()) {
                // Don't do anything UI if Activity is finishing.
                return;
            }

            // Should not allow access. In most cases, the app should assume
            // the user has access unless it encounters this. If it does,
            // the app should inform the user of their unlicensed ways
            // and then either shut down the app or limit the user to a
            // restricted set of features.

        }

        public void applicationError(int errorCode) {

            Log.d(tag,"License - application error code "+errorCode);

            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // This is a polite way of saying the developer made a mistake
            // while setting up or calling the license checker library.
            // Please examine the error code and fix the error.

        }
    }

    @Override
    protected void onDestroy()
    {
    mChecker.onDestroy();
    super.onDestroy();
    }
}

OK, I've solved it. 好的,我已经解决了。 Error 6 isn't coming from LicenceValidator, it's coming from LicenseChecker and indicates that a permission is missing. 错误6不是来自LicenceValidator,它来自LicenseChecker,表示缺少权限。 I hadn't given the app com.android.vending.CHECK_LICENSE permission. 我没有给app com.android.vending.CHECK_LICENSE权限。 When I did, it started working. 当我这样做时,它开始工作。

Thanks for your interest and I hope this helps anyone who makes the same mistake. 感谢您的关注,我希望这可以帮助任何犯同样错误的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM