Android许可申请不起作用?

Kha*_*han 7 java android android-lvl

我通过阅读官方说明实施了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();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我给出的明确许可

<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"/>
Run Code Online (Sandbox Code Playgroud)

实现这个后我运行应用程序,并与释放钥匙签署,并在APK上传为草稿谷歌Play开发者控制台 ,我还增加了3测试账号在开发者控制台的设置.

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

但在我的情况下,在所有设备中它将工作正常,这件事发生一些奇怪的情况,如果互联网断开,它将显示关于盗版的对话,如果它是连接,而不是它在所有设备,尽管测试帐户设备.

Kha*_*han 2

最后我找到了测试谷歌许可证检查器的正确方法。

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

最后,我以这种方式进行测试,添加了测试帐户,并在开发人员控制台中选择“许可证测试响应”作为“许可”,应用程序将运行,并且在我还使用“ NOT_LICENSED”更改开发人员控制台中的设置后,它显示了有关具有测试帐户的设备中的盗版的对话框作为主账户。

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