在设备上的Andr​​oid授权服务器 [英] Android Licensing Server on a device

查看:124
本文介绍了在设备上的Andr​​oid授权服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚整个Android的许可的事,感到沮丧。 在模拟器中,我跑没有帐户,或者一个不是在测试环境中的应用程序,它似乎正常工作,并返回未授权的响应,并弹出购买应用程序现在消息。

I'm trying to figure out the whole Android licensing thing, and getting frustrated. In the emulator, I run the app with no account, or one that isn't in the testing environment, and it seems to work correctly, returning the not licensed response and pops up the buy the app now message.

当我尝试在实际的Andr​​oid设备上运行它,它会返回行货每一次,即使该设备帐户不是一个是在测试环境中。 此外,尽管它返回行货,检查许可证中永远不会消失,除非你单击取消。然后,它只是让你使用的应用程序,就好像它被授权。 它主要是C和,P从这个例子中,有一些变化。我删除了检查许可按钮和状态文本框。

When I try to run it on an actual Android device, it returns licensed every time, even though the device account isn't one that is in the testing environment. Also, even though it returns licensed, the "checking license" box never goes away, unless you click cancel. Then it just lets you use the app as if it was licensed. It's mostly C&P from the example, with a few changes. I removed the check license button and the status text box.

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

    mHandler = new Handler();

    // Try to use more data here. ANDROID_ID is a single point of attack.
    String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

    // Library calls this when it's done.
    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();

    ArrayAdapter<String> booksAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mBooks);

    this.setListAdapter(booksAdapter);
}

protected Dialog onCreateDialog(int id) {
    // We have only one dialog.
    return new AlertDialog.Builder(this)
        .setTitle(R.string.unlicensed_dialog_title)
        .setMessage(R.string.unlicensed_dialog_body)
        .setPositiveButton(R.string.buy_button, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                    "http://market.android.com/details?id=" + getPackageName()));
                startActivity(marketIntent);
                finish();
            }
        })
        .setNegativeButton(R.string.quit_button, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        })
        .create();
}

private void doCheck() {
    setProgressBarIndeterminateVisibility(true);
    alertbox("status", getString(R.string.checking_license));
    mChecker.checkAccess(mLicenseCheckerCallback);
}

protected void alertbox(String title, String mymessage)  
{  
    new AlertDialog.Builder(this)  
       .setMessage(mymessage)  
       .setTitle(title)  
       .setCancelable(true)  
       .setNeutralButton(android.R.string.cancel,  
          new DialogInterface.OnClickListener() {  
          public void onClick(DialogInterface dialog, int whichButton){}  
         })  
      .show();  
}

private void displayResult(final String result) {
    mHandler.post(new Runnable() {
        public void run() {
            alertbox("status", result);

            setProgressBarIndeterminateVisibility(false);
        }
    });
}

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

        //displayResult(getString(R.string.allow));
    }

    public void dontAllow() {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        //displayResult(getString(R.string.dont_allow));

        // 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.
        // In this example, we show a dialog that takes the user to Market.
        showDialog(0);
    }

    public void applicationError(ApplicationErrorCode 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.
        String result = String.format(getString(R.string.application_error), errorCode);
        displayResult(result);
    }
}

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

我不知道我需要改变,使其工作......或在许可证以某种方式缓存(尽管这是我第一次在此设备上运行它),如果我可以取消缓存它无需擦拭设备,因为那将是很好的,当我做测试的其他应用程序。 另外,我怎么删除检查许可证的信息,而无需点击取消按钮......我只是做它,使它不显示?

I just don't know what I need to change to make it work... or if the license is somehow cached (even though this is the first time I've run it on this device) and if I can uncache it without wiping the device, as that'll be nice for when I do testing on other apps. Also, how do I remove the "checking license" message without having to click the cancel button... should I just make it so that it doesn't show up?

推荐答案

我刚刚进入自己的牌,所以不要以此为福音,但几件事情坚持了:

I'm just getting into licensing myself so don't take this as gospel but a few things stick out:

或许可以某种方式缓存(尽管这是我第一次在此设备上运行它),如果我可以取消缓存它无需擦拭设备,因为那将是很好的,当我做测试的其他应用程序。

or if the license is somehow cached (even though this is the first time I've run it on this device) and if I can uncache it without wiping the device, as that'll be nice for when I do testing on other apps.

您使用的是 ServerManagedPolicy ,以便批准的的缓存和混淆。这是推荐的方式来做到这一点。 (我假设,以提供更好的用户体验和更好的响应时间)。为了调试你的认可,你需要登录到您的市场概况并改变测试响应选项。您需要使用具有相同的帐户作为发布商资料中的设备的测试响应工作,对未释放到市场上还没有一个应用程序。

You are using the ServerManagedPolicy so the approval will be cached and obfuscated. This is the recommended way to do it. ( I assume to provide a better user experience and better response time ) In order to debug your approval you need to log into your market profile and change the "Test response" option. You need to use a device that has the same account as your publisher profile for the test response to work for a app that isn't released to the market yet.

您还没有code在允许()方法为您MyLicenseCheckerCallback类,它也许应该是在那里你清除对话框(外isFinishing条件)。

You also have no code in your allow() method for your MyLicenseCheckerCallback class which should probably be where you clear the dialog (outside the isFinishing conditional).

如果我可以取消缓存它无需擦拭设备,因为那将是不错的,当我做对其他应用程序测试

if I can uncache it without wiping the device, as that'll be nice for when I do testing on other apps

根据LicenseValidator.java看起来批准存放在com.android.vending.licensing.ServerManagedPolicy私人模式preFS文件。您可以使用共享preferences编辑从应用程序中的另一个地方清除它。

Based on LicenseValidator.java It looks like the approval is stored in a prefs file at com.android.vending.licensing.ServerManagedPolicy in private mode. You can use the sharedpreferences editor to clear it from another place in the app.

再次声明,我不是这一个亲又那么我可能是错的,但我想你也许可以,如果你得到它的配置来解决你的错误的权利。

Again I'm not a pro on this yet so I could be wrong but I think you might be able to troubleshoot your bug if you get it configured right.

这篇关于在设备上的Andr​​oid授权服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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