【问题标题】:Android licensing application not works?Android 许可应用程序不起作用?
【发布时间】:2018-12-16 12:42:11
【问题描述】:

我通过阅读 the official instructions 实现了 Google 许可证检查器。

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings.Secure;
import android.widget.Toast;

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 Splash extends Activity {
    MyLicenseCheckerCallback mLicenseCheckerCallback;
    LicenseChecker mChecker;
    byte[] SALT = new byte[] { -73, 95, 70, -126, -103, -57, 14, -46, 51, 88, -5,
        -60, 77, -88, -63, -13, -1, 82, -4, 9 };
    //Handler mHandler;
    String BASE64_PUBLIC_KEY="My base key";
    Context mContext;
    IBinder serviceBinder;
    String deviceId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        mLicenseCheckerCallback = new MyLicenseCheckerCallback();
        deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
        // Construct the LicenseChecker with a policy.
        mChecker = new LicenseChecker(this,
            new ServerManagedPolicy(Splash.this, new AESObfuscator(SALT,
                getPackageName(), deviceId)), BASE64_PUBLIC_KEY);
        doCheck();
    }

    private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
        @Override
        public void allow(int reason) {
            // TODO Auto-generated method stub
            if (isFinishing())
                return; // Don't update UI if Activity is finishing.
            // Toast.makeText(Splash.this, "Success", Toast.LENGTH_LONG).show();
            Intent intent=new Intent(Splash.this,Main.class);
            startActivity(intent);
            finish();

            // Should allow user access.
            // so do nothing
        }

        @Override
        public void dontAllow(int reason) {
            // TODO Auto-generated method stub
            if (isFinishing())
                return; // Don't update UI if Activity is finishing.
            // Toast.makeText(Splash.this, "Fail", Toast.LENGTH_LONG).show();
            createDialog();
        }

        @Override
        public void applicationError(int errorCode) {
            // TODO Auto-generated method stub
        }
    }

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

    private void doCheck() {
        // mCheckLicenseButton.setEnabled(false);
        setProgressBarIndeterminateVisibility(true);
        ///  mStatusText.setText(R.string.checking_license);
        mChecker.checkAccess(mLicenseCheckerCallback);
    }

    public void createDialog(){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("PIRACY WARNING");
        builder.setMessage("A valid purchase for My App has not been detected.  Your IP"
            + " has been logged and all offenders will be reported to the authorities."
            + " If you received this message in error, please contact Support.");
        builder.setPositiveButton("Buy Now", 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);
            }
        });
        builder.setNegativeButton("Quit", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    }
}

这是我给予的清单许可

<supports-screens android:normalScreens="true" android:largeScreens="true" android:smallScreens="true" android:anyDensity="true" android:xlargeScreens="true" android:resizeable="true"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

实施此操作后,我运行应用程序并使用发布密钥对其进行签名,并将 apk 作为草稿上传到 google play 开发者控制台,我还在开发者控制台设置中添加了 3 个测试帐户。

根据我的阅读和理解,必须在设备中运行测试帐户作为设备中的主帐户,而设备的其余部分必须显示对话框。

但在我的情况下,在所有设备上它都可以正常工作,并且如果互联网断开连接,它会显示有关盗版的对话框,并且如果它已连接,那么它会在所有设备上工作,尽管有测试帐户设备。

【问题讨论】:

    标签: java android android-lvl


    【解决方案1】:

    我终于找到了测试 google license checker 的正确方法。

    当我在 google play 开发者控制台中上传 apk 作为草稿和 如果我在任何设备上安装该 apk,如果设备中没有使用测试帐户登录,它将运行响应 LICENSED

    最后我以这种方式进行测试,我添加了测试帐户,并在开发者控制台中选择 License Test Response 作为 LICENSED,然后应用程序将运行,之后我还更改了设置带有 NOT_LICENSED 的开发者控制台,它会在以测试帐户作为主帐户的设备中显示有关盗版的对话框。

    重要提示:除了测试帐户设备之外,它运行响应 LICENSED 因为我在 Play 商店中将 APK 作为草稿上传。所以对于测试 google 许可,我们必须只考虑在 Google Play 开发者控制台中添加的测试帐户

    【讨论】:

    • 它对我不起作用....请帮助我。我按照你说的做了,但是每次盗版对话都会弹出
    • 您必须在 google play 开发者控制台中添加测试 gmail 帐户,并且在设备中您必须将该帐户作为主要 gmail 帐户,用于从 Play 商店下载应用程序。以及我提到的许可证测试响应您需要选择 LICENSED 而不是 NOTLICENSED 或任何其他选项。
    • 我不断收到错误消息,“错误:(48, 0) com.android.vending.CHECK_LICENSE 的描述无效”。有机会有人知道为什么吗?非常感谢。
    【解决方案2】:

    您已经完成了所有这些步骤,但再次清楚地检查了一遍:

    1. 检查您的公钥与草稿存储公钥比较后。
    2. 给自己的盐 20 个数字。
    3. 在 google play 中正确提供测试帐户和相同帐户 也可以在设备中使用。
    4. 在 google play 中,您必须为应用草稿设置许可模式。
    5. 过一段时间后检查,因为需要一些时间才能给出有效结果。
    6. 最终验证应用程序中的警报对话框条件。
    7. 清除手机中的 google play 缓存可能会存储结果。

    【讨论】:

      【解决方案3】:

      LVL 正在使用您添加的帐户的所有设备上工作,而不仅仅是主帐户。它不适用于具有您未添加到开发者控制台的帐户的手机。甚至,LVL 尝试使用 google LVL -Server 验证您的应用程序,因此您需要互联网连接,这没关系。如果您只想检查一次许可证,您必须保存一些数据,例如在共享首选项中,检查已经完成。因此,下次启动应用程序时,您可以检查这些保存的共享首选项,如果该应用程序刚刚通过验证。如果是,不要再检查,如果不是,再试一次。

      您可以在开发者控制台中设置检查许可证的行为,您可以模拟一个正常的响应,或者例如一个“未验证”的响应等等......

      【讨论】:

      • 在我的情况下,它也适用于我尚未在开发者控制台中添加其帐户的设备,这意味着应用程序在所有设备中都可以运行
      • 好吧,我理解错了。你真的,真的确定在其他设备上没有测试帐户。我的意思是,可以有多个帐户,也许这台设备上也有测试帐户?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多