Android的许可申请不工作? [英] Android licensing application not works?

查看:163
本文介绍了Android的许可申请不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了谷歌授权cheker通过阅读官方说明

I implemented Google License cheker by reading the official instructions.

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();
    }
}

和这里是我给出的menifest许可

and here is the menifest permission which i given

<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在选秀结束后的谷歌Play开发者控制台,然后我也加入开发者控制台设置3个测试帐号。

after implementing this I run app in and sign it with with release key and uploaded apk as draft in google play developer console and I have also added 3 test account in setting of developer console.

根据我阅读和理解,必须在具有器件和设备的其他部分测试帐户为主要考虑该设备上运行它必须显示对话框。

As per I read and understand the must be run in the device which having the test account as main account in device and rest of the device it would have to show the dialog.

不过,在我的情况在所有的设备它会工作正常,这件事情发生的一些奇怪的情况,如果网络连接断开比将显示对话框有关盗版,如果它是连接比它worsk在测试帐号devies所有设备inspite。

But in my case in all device it will works fine and this thing happen some strange situation if internet is disconnected than it will show dialog about piracy and if it is connected than it worsk in all device inspite of the test account devies.

推荐答案

最后,我发现谷歌的许可检查测试的正确方法。

Finally I found the proper way of testing of google license checker.

我在谷歌上载的apk Play开发者控制台的草案 如果我安装的APK在任何设备比将与响应执行许可如果在设备中没有登录与测试账号。

As I uploaded apk in google play developer console as draft and If I install that apk in any device than it will run with response LICENSED if in the device is not having login with test account.

最后,我做测试这样我加入的测试帐户,我选择授权测试回应在开发者控制台的许可比应用程序将运行后,我也改变设置与开发者控制台的 NOT_LICENSED 比它显示了有关盗版具有测试帐号作为主要考虑该设备对话框。

And finally I do testing this way I added test account and i select License Test Response in developer console as LICENSED than app will run and after i also change setting in developer console with NOT_LICENSED than it shows dialog about piracy in the device which having test account as main account.

重要提示:与比它的响应运行测试帐号设备等的许可怎么一回事,因为我是在玩store.So上传的APK的草案,以供测试谷歌的许可,我们必须要考虑在谷歌只增加了测试帐户Play开发者控制台

IMPORTANT NOTE :And other than test account devices it run with the response LICENSED beacuse is I uploaded APK as draft in play store.So for the testing google licensing we must have to consider only test account added in Google Play Developer Console

这篇关于Android的许可申请不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆