Android的许可证检查直去的ApplicationError(...) [英] Android license check going straight to applicationError(...)

查看:151
本文介绍了Android的许可证检查直去的ApplicationError(...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在实现我的应用程序在Android服务器检查。我使用的方法StrictPolicy,因为我可能是刚刚从盗版有点苦有5倍的下载作为市场的版本数量......反正我codeD的方法基本上逐字到我的源$ C ​​$ C。然而,当我切换开发者控制台许可的许可测试响应,我得到的无牌对话框。然而,在方法的ApplicationError,dontAllow()被调用,当我走出注释此行,无牌对话框不显示。我究竟做错了什么?
这是我MyLicenseCheckerCallback类。

我在onResume调用doCheck在OnCreate,周而复始。

  @覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    mHandler =新的处理程序();
    mLicenseCheckerCallback =新MyLicenseCheckerCallback();    //构造一个政策LicenseChecker。
    mChecker =新LicenseChecker(
        对此,新ServerManagedPolicy(这一点,
            新AESObfuscator(SALT,getPackageName(),DEVICEID))
            BASE64_PUBLIC_KEY
            );
    doCheck();    的setContentView(R.layout.main);
    ...
私人无效doCheck(){
    mChecker.checkAccess(mLicenseCheckerCallback);
}私有类MyLicenseCheckerCallback实现LicenseCheckerCallback {
    公共无效允许(){
        如果(isFinishing()){
            //如果活动是整理不更新UI。
            返回;
        }
        //应该允许用户访问。
    }    公共无效dontAllow(){
        如果(isFinishing()){
            //如果活动是整理不更新UI。
            返回;
        }
        //要尽可能恼人
        illegalDownload =新的IllegalDownloadHandler(speedy.this);
        illegalDownload.show();
        illegalDownload.setOnDismissListener(新OnDismissListener(){
                @覆盖
                公共无效onDismiss(DialogInterface对话){
                    意向goToMarket = NULL;
                    goToMarket =新意图(Intent.ACTION_VIEW,Uri.parse(市场://细节ID = com.TimothyMilla.Speed​​Boost));
                    startActivity(goToMarket);
                    illegalDownload.dismiss();
                }
        });
        //不应该允许访问。应用程序可以处理的需要,
        //通常通过通知应用程序是不许可的用户
        //然后关闭应用程序或限制用户在
        //限制的功能集。
        //在这个例子中,我们显示一个对话框,将用户带到市场。
        //的ShowDialog(0);
        //的onDestroy();
    }    @覆盖
    公共无效的ApplicationError(的ApplicationError code错误code){
        // TODO自动生成方法存根
        dontAllow();
        //当我评论上述行了,不显示未经许可对话框。
    }    私人无效displayResult(最后弦乐结果){
        mHandler.post(新的Runnable(){
            公共无效的run(){
                // dontAllow();
                Toast.makeText(getApplicationContext(),结果,Toast.LENGTH_SHORT).show();
                // setProgressBarIndeterminateVisibility(假);
            }
        });
    }
}


解决方案

既然你没有更新我的意见,我的猜测......确保你:

1 - 正确地复制你的公钥。

2 - 填充的DeviceID,因为我认为你是。只是确保,因为你的code上面隐藏了上述声明。但是,因为这会让你编译错误,我敢肯定你。

3改变了响应code。在开发者控制台(你说你)。

4-最后,您包含在Android清单文件的适当权限:

 <使用许可权的android:NAME =android.permission.READ_PHONE_STATE/>
<使用许可权的android:NAME =com.android.vending.CHECK_LICENSE/>

I just implemented the android server check in my app. I am using the StrictPolicy method because I may be just a little bitter from the pirated version have 5X the amount of downloads as the version in the market... Anyway, I coded the method basically verbatim into my source code. However, when I toggle the License Test Response on the developer console to Licensed, I get the unlicensed dialog. However, in the applicationError method, dontAllow() is called and when i comment this line out, the unlicensed dialog does not show. What am I doing wrong? Here is my MyLicenseCheckerCallback class.

I call doCheck in the onCreate, and again in the onResume.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHandler = new Handler();
    mLicenseCheckerCallback = new MyLicenseCheckerCallback();

    // Construct the LicenseChecker with a Policy.
    mChecker = new LicenseChecker(
        this, new ServerManagedPolicy(this,
            new AESObfuscator(SALT, getPackageName(), deviceId)),
            BASE64_PUBLIC_KEY
            );
    doCheck();

    setContentView(R.layout.main);
    ...


private void doCheck() {
    mChecker.checkAccess(mLicenseCheckerCallback);
}

private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
    public void allow() {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        // Should allow user access.
    }

    public void dontAllow() {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        //Be as annoying as possible
        illegalDownload = new IllegalDownloadHandler(speedy.this);
        illegalDownload.show();
        illegalDownload.setOnDismissListener(new OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    Intent goToMarket = null;
                    goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.TimothyMilla.SpeedBoost"));
                    startActivity(goToMarket);
                    illegalDownload.dismiss();
                }
        });
        // Should not allow access. An app can handle as needed,
        // typically by informing the user that the app is not licensed
        // and then shutting down the app or limiting the user to a
        // restricted set of features.
        // In this example, we show a dialog that takes the user to Market.
        //showDialog(0);
        //onDestroy();
    }

    @Override
    public void applicationError(ApplicationErrorCode errorCode) {
        // TODO Auto-generated method stub
        dontAllow();
        //when I comment the above line out, the unlicensed dialog is not shown.
    }

    private void displayResult(final String result) {
        mHandler.post(new Runnable() {
            public void run() {
                //dontAllow();
                Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
                //setProgressBarIndeterminateVisibility(false);
            }
        });
    }
}

解决方案

Since you didn't update my comment, my guesses... make sure you:

1- copied your public key correctly.

2- populated deviceId, as I think you are. Just making sure because your code above is hiding that declaration. But since it would throw compile errors at you, I'm sure you are.

3- changed the response code in the developer console (you said you have).

4- Finally, that you included the proper permissions in the Android manifest file:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />

这篇关于Android的许可证检查直去的ApplicationError(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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