我正在我的应用程序中实现licensing,但没有找到响应代码的正式列表。
返回代码(int policyReason
)的脚本是这样的:
private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
public void allow(int policyReason) {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
// Should allow user access.
displayResult(getString(R.string.allow));
}
public void dontAllow(int policyReason) {
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 a deep
// link returned by the license checker.
// If the reason for the lack of license is that the service is
// unavailable or there is another problem, we display a
// retry button on the dialog and a different message.
displayDialog(policyReason == Policy.RETRY);
}
public void applicationError(int 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);
}
}
我发现了这些here(非官方的链接提供了指向没有int代码的正式文档的指向):
Response Code Value Licensed 256 Not_licensed 561 Error_Server_Failure 291 Error_Contacting_Server 291 Error_Not_Market_Managed 3 Error_Invalid_Package_Name 1 Error_Non_Matching_UID 2
以及以下here(非官方,未链接到带有int代码的官方文档):
LICENSED = Hex: 0x0100, Decimal: 256 NOT_LICENSED = Hex: 0x0231, Decimal: 561 RETRY = Hex: 0x0123, Decimal: 291 LICENSED_OLD_KEY = Hex: 0x2, Decimal: 2 ERROR_NOT_MARKET_MANAGED = Hex: 0x3, Decimal: 3 ERROR_SERVER_FAILURE = Hex: 0x4, Decimal: 4 ERROR_OVER_QUOTA = Hex: 0x5, Decimal: 5 ERROR_CONTACTING_SERVER = Hex: 0x101, Decimal: 257 ERROR_INVALID_PACKAGE_NAME = Hex: 0x102, Decimal: 258 ERROR_NON_MATCHING_UID = Hex: 0x103, Decimal: 259
但是在LicenseValidator
类的官方文档中有以下内容:
// Server response codes.
private static final int LICENSED = 0x0;
private static final int NOT_LICENSED = 0x1;
private static final int LICENSED_OLD_KEY = 0x2;
private static final int ERROR_NOT_MARKET_MANAGED = 0x3;
private static final int ERROR_SERVER_FAILURE = 0x4;
private static final int ERROR_OVER_QUOTA = 0x5;
private static final int ERROR_CONTACTING_SERVER = 0x101;
private static final int ERROR_INVALID_PACKAGE_NAME = 0x102;
private static final int ERROR_NON_MATCHING_UID = 0x103;
(编辑)例如,policyReason
可能返回291
和256
,但它们不在LicenseValidator
中(0x101
= 257
,0x102 =
258 ,
0x103 =
259`)。
在哪里可以找到官方文档,其中包含要依赖的int响应代码列表?
我已经在lvl-library
模块中进行了搜索,但没有成功。
(edit2)感谢@Mir Milad Hosseiny的回答,现在我确切地知道在哪里可以找到这些int代码。但是现在我有一个疑问:为什么允许应该返回RETRY或NOT_LICENSED并不允许RETRY和LICENSED?由于它们的名称,它们应该只返回LICENSED和NOT_LICENSED / RETRY。当用户确实从Google Play下载我的应用程序时,我必须知道如何正确处理该情况。 I asked a dedicated question about that here 。
非常感谢!
答案 0 :(得分:1)
看看Android开发者网站上的Licensing Reference官方页面。
更新
LicenseCheckerCallback类上有3种回调方法。
1。公共无效允许(原因不明)
@param原因通常为Policy.LICENSED或Policy.RETRY。 (尽管从理论上讲该策略也可以在此处返回Policy.NOT_LICENSED)
2。公共无效dontAllow(原因)
@param原因Policy.NOT_LICENSED或Policy.RETRY。 (尽管从理论上讲,该策略也可以在此处返回Policy.LICENSED,例如,对LVL的调用花费了太长时间)
3。公共无效applicationError(int errorCode)
应用程序代码错误。呼叫者未正确呼叫或设置许可证检查器。应该被认为是致命的。
对于第一种和第二种方法,输入值reason
是{{3}上可用的Policy.LICENSED
,Policy.NOT_LICENSED
和Policy.RETRY
值之一}类源代码如下:
/**
* LICENSED means that the server returned back a valid license response
*/
public static final int LICENSED = 0x0100;
/**
* NOT_LICENSED means that the server returned back a valid license response
* that indicated that the user definitively is not licensed
*/
public static final int NOT_LICENSED = 0x0231;
/**
* RETRY means that the license response was unable to be determined ---
* perhaps as a result of faulty networking
*/
public static final int RETRY = 0x0123;
对于第三种方法,LicenseCheckerCallback类源代码上的错误代码如下:
/** Application error codes. */
public static final int ERROR_INVALID_PACKAGE_NAME = 1;
public static final int ERROR_NON_MATCHING_UID = 2;
public static final int ERROR_NOT_MARKET_MANAGED = 3;
public static final int ERROR_CHECK_IN_PROGRESS = 4;
public static final int ERROR_INVALID_PUBLIC_KEY = 5;
public static final int ERROR_MISSING_PERMISSION = 6;
此外,您可以检查Policy和LicenseValidator类的源代码,以检查传递给这3个方法的输入值是否与它们的文档一致。