gpt4 book ai didi

android - 使用 Android 许可证服务器的奇怪错误

转载 作者:行者123 更新时间:2023-11-30 00:56:15 26 4
gpt4 key购买 nike

所以按照官方 android 开发者网站的说明,我已经设置了所有内容来创建许可证检查,但是我遇到了最奇怪的错误......

我为来自许可服务器的 3 个可能响应创建了 3 个 Activity :

-EverythingOkActivity

-NotLicensedActivity

-错误 Activity

每个都应该根据服务器的响应启动,但是......

当我连接手机调试我的应用程序时,如果满足启动 ErrorActivity 的条件,那么它会启动 NotLicensedActivity Intent ,反之亦然,如果满足满足启动 NotLicensedActivity Intent ,然后启动 ErrorActivity Intent 。

此外,我永远无法启动 EverythingOkActivity,我已经在开发人员控制台上设置了我的测试 gmail 帐户,并在我的许可测试响应中选择了LICENSED帐户,我还上传了 APK。

调试控制台显示来自服务器的响应:

I/LicenseChecker: Received response.
I/LicenseChecker: Clearing timeout.

但没有错误至少我没有互联网,在那种情况下显示:

I/LicenseChecker: Received response.
I/LicenseChecker: Clearing timeout.
W/LicenseValidator: Error contacting licensing server.

然后将 Intent 启动到 NotLicensedActivity 而不是 ErrorActivity

我不知道哪里出了问题,对不起,如果我是 Android 菜鸟。

这是我的主要 Activity 的代码:

import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import com.google.android.vending.licensing.AESObfuscator;
import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.LicenseCheckerCallback;
import com.google.android.vending.licensing.ServerManagedPolicy;

public class MainActivity extends AppCompatActivity {
private static final String BASE64_PUBLIC_KEY = "MIIBIjANBgkq[...]";
private static final byte[] SALT = new byte[] {
-44, 55, 30, -128, -103, -57, 74, -64, 51, 88, -95, -45, 77, -117, -36, -113, -11, 32, -64,
89
};
private LicenseCheckerCallback mLicenseCheckerCallback;
private LicenseChecker mChecker;
private boolean keepGoing = true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String deviceId = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ANDROID_ID);
mLicenseCheckerCallback = new MyLicenseCheckerCallback();
mChecker = new LicenseChecker(this, new ServerManagedPolicy(this,
new AESObfuscator(SALT, getPackageName(), deviceId)),
BASE64_PUBLIC_KEY);
doCheck();
}
@Override
public void onResume() {
super.onResume();
if (!keepGoing) {
finish();
}
}
private void doCheck() {
mChecker.checkAccess(mLicenseCheckerCallback);
}
private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
public void allow(int policyReason) {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
Intent intent = new Intent(MainActivity.this, EverythingOkActivity.class);
startActivity(intent);
}
public void dontAllow(int policyReason) {
if (isFinishing()) {
return;
}
keepGoing = false;
Intent intent = new Intent(MainActivity.this, NotLicensedActivity.class);
startActivity(intent);
}
public void applicationError(int errorCode) {
if (isFinishing()) {
return;
}
keepGoing = false;
Intent intent = new Intent(MainActivity.this, ErrorActivity.class);
startActivity(intent);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
mChecker.onDestroy(); //Don't forget this line. Without it, your app might crash.
}
}

最佳答案

我解决了!!!问题是该应用程序需要至少作为 Alpha 版本在 Play 商店中发布,然后您需要向该应用程序添加一个 Alpha 测试用户(在本例中是我自己)的列表。仅上传 APK 是不够的,您需要实际发布应用程序才能获得工作许可证。我将以该代码为例,因为它很有魅力。干杯(^_^)

关于android - 使用 Android 许可证服务器的奇怪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40116480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com