English 中文(简体)
无服务器/服务机的安检
原标题:Android Licensing check with no server/service available

I have an app and I am attempting to add the google licensing instead of the copy right protection.

My issue is: When the device can connect there is no issue and if there is a license then it grants the access. If the device can connect and there is no license then it denies access.

当该装置由于飞机方式、死亡区等原因能够连接NOT时,该仪器可提供未经许可的反应。

Here is my code: package "package name";

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

import com.android.vending.licensing.AESObfuscator;
import com.android.vending.licensing.LicenseChecker;
import com.android.vending.licensing.LicenseCheckerCallback;
import com.android.vending.licensing.ServerManagedPolicy;


public class LicenseCheck extends Activity {
    private class MyLicenseCheckerCallback implements LicenseCheckerCallback {

        @Override
        public void allow() {
            if (isFinishing()) {
                // Don t update UI if Activity is finishing.
                return;
            }
            // Should allow user access.
            startMainActivity();

        }


        @Override
        public void applicationError(ApplicationErrorCode errorCode) {
            if (isFinishing()) {
                // Don t update UI if Activity is finishing.
                return;
            }
            // This is a polite way of saying the developer made a mistake
            // while setting up or calling the license checker library.
            // Please examine the error code and fix the error.
            toast("Error: " + errorCode.name());
            startMainActivity();

        }

        @Override
        public void dontAllow() {
            if (isFinishing()) {
                // Don t update UI if Activity is finishing.
                return;
            }

            // Should not allow access. In most cases, the app should assume
            // the user has access unless it encounters this. If it does,
            // the app should inform the user of their unlicensed ways
            // and then either shut down the app or limit the user to a
            // restricted set of features.
            // In this example, we show a dialog that takes the user to Market.
            showDialog(0);
        }
    }



    private static final String BASE64_PUBLIC_KEY =     "MY KEY";

private static final byte[] SALT = new byte[] { "20 RANDOM INTEGERS"  };
private LicenseChecker mChecker;

// A handler on the UI thread.

private LicenseCheckerCallback mLicenseCheckerCallback;

private void doCheck() {

    mChecker.checkAccess(mLicenseCheckerCallback);
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Try to use more data here. ANDROID_ID is a single point of attack.
    String deviceId = Secure.getString(getContentResolver(),
            Secure.ANDROID_ID);

    // Library calls this when it s done.
    mLicenseCheckerCallback = new MyLicenseCheckerCallback();
    // Construct the LicenseChecker with a policy.
    mChecker = new LicenseChecker(this, new ServerManagedPolicy(this,
            new AESObfuscator(SALT, getPackageName(), deviceId)),
            BASE64_PUBLIC_KEY);
    doCheck();

}

@Override
protected Dialog onCreateDialog(int id) {
    // We have only one dialog.
    return new AlertDialog.Builder(this)
            .setTitle("Application Not Licensed")
            .setCancelable(false)
            .setMessage(
                    "This application is not licensed. Please purchase it from the Android Market")
            .setPositiveButton("Buy App",
                    new DialogInterface.OnClickListener() {
                        @Override
                        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);
                            finish();
                        }
                    })
            .setNegativeButton("Exit",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog,
                                int which) {
                            finish();
                        }
                    }).create();
}

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

private void startMainActivity() {
    startActivity(new Intent(this, MY_Activity.class));  
    finish();
}

public void toast(String string) {
    Toast.makeText(this, string, Toast.LENGTH_SHORT).show();
}

}

I am even willing to only block access if it only comes back NO License. I would much rather check each time the app runs and the server is available. Even if I could run a check to see if it can reach the server and go from there.

问题回答

我找到了一个工作。 我没有找到解决办法。 在进行了详尽的研究之后,我发现,如果没有连接,或以飞机方式,许可检查自动拖欠NOT_LICENSED。

我所做的是检查连通性。 如果连接起来,则进行许可证检查。 如果没有连接,就只能与主要活动连接。

或许,你会与LVL图书馆使用一个测试账户。 在使用谷歌试验账户时,许可证有效期只有1分钟,在分钟后,任何进一步的许可检查都需要有净机会回复。 如果有购买该套用具的真实账户,有效的许可回复将安排几天时间(假设你正在使用服务器管理)。

public void dontAllow(int policyReason) {

   if (isFinishing()) {
       // Don t update UI if Activity is finishing.
       return;
    }

    if (policyReason == Policy.RETRY) {
        //-- no connection (unable to validate license).
    } else { 
        //-- no license (application is not licensed).
    }

    showDialog(0);
}




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签