这实际上非常简单,您不需要使用任何 Activity 类来实现 WallpaperService 的许可。
确保您已仔细按照http://developer.android.com/guide/publishing/licensing.html上的说明进行操作
我是这样做的:
您的扩展 Engine 类应包含类似于以下内容的内容...(对您的问题不重要的代码已被删除)
class startYourEngines extends Engine {
public startYourEngines() {
super();
licenseStatus(); //custom license check method (for modularity)
//the rest of your engine would go here
}
public void onDestroy() {
super.onDestroy();
licenseChecker.onDestroy(); //we call this to close IPC connections
}
//prep work
private static final String BASE64_PUBLIC_KEY = //OMITTED//;
private LicenseCheckerCallback licenseCallback;
private LicenseChecker licenseChecker;
private byte[] salt = "rAnd0mStr!ng".getBytes();
private AESObfuscator aes;
private String deviceId;
//our custom license check method
private void licenseStatus() {
deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
aes = new AESObfuscator(salt, getPackageName(), deviceId);
licenseCallback = new licenseVerification();
licenseChecker = new LicenseChecker(context, new ServerManagedPolicy(context, aes), BASE64_PUBLIC_KEY);
licenseChecker.checkAccess(licenseCallback);
}
//our callback method
private class licenseVerification implements LicenseCheckerCallback {
@Override
public void allow() {
//allow full app use
}
@Override
public void dontAllow() {
//prevent or limit app use
}
@Override
public void applicationError(ApplicationErrorCode errorCode) {
//error handling here
}
}
}
Android 平台上的许可在创建时考虑到了多功能性。请务必通读文档,您应该没有任何问题。