Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8151795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:30:22+00:00 2026-06-06T15:30:22+00:00

My app is ready for submission now but I have recently learnt about Licensing.

  • 0

My app is ready for submission now but I have recently learnt about Licensing.

I have found a step by step by tutorial online: http://twistbyte.com/tutorial/using-the-android-licensing-service-step-by-step

I have imported the Licensing library into Eclipse and created the LicenseCheckActivity class as described in the tutorial.

I am on the final step of the tutorial, point number 7. The tutorial says my class should extend LicenseCheckActivity. However, the class in which I would like to check for licensing already extends Activity.

How can I use the checkLicense() method from my LicenseCheckActivity class?

Here is my code:

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    // Check the license
    LicenseCheckActivity  l = new LicenseCheckActivity();
    checkLicense();

This gives me the following error:

Cannot instantiate the type LicenseCheckActivity

Here is my LicenseCheckActivity class

public abstract class LicenseCheckActivity extends Activity {

static boolean licensed = true;
static boolean didCheck = false;
static boolean checkingLicense = false;
static final String BASE64_PUBLIC_KEY = "MY BASE KEY";

LicenseCheckerCallback mLicenseCheckerCallback;
LicenseChecker mChecker;

Handler mHandler;

SharedPreferences prefs;

// REPLACE WITH YOUR OWN SALT , THIS IS FROM EXAMPLE
private static final byte[] SALT = new byte[] { -46, 65, 30, -128, -103,
        -57, 74, -64, 51, 88, -95, -45, 77, -117, -36, -113, -11, 32, -64,
        89 };

private void displayResult(final String result) {
    mHandler.post(new Runnable() {
        public void run() {

            setProgressBarIndeterminateVisibility(false);

        }
    });
}

protected void doCheck() {

    didCheck = false;
    checkingLicense = true;
    setProgressBarIndeterminateVisibility(true);

    mChecker.checkAccess(mLicenseCheckerCallback);
}

protected void checkLicense() {

    Log.i("LICENSE", "checkLicense");
    mHandler = new Handler();

    // Try to use more data here. ANDROID_ID is a single point of attack.
    String deviceId = Settings.Secure.getString(getContentResolver(),
            Settings.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);

    // mChecker = new LicenseChecker(
    // this, new StrictPolicy(),
    // BASE64_PUBLIC_KEY);

    doCheck();
}

protected class MyLicenseCheckerCallback implements LicenseCheckerCallback {

    public void allow() {
        Log.i("LICENSE", "allow");
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        // Should allow user access.
        displayResult(getString(R.string.allow));
        licensed = true;
        checkingLicense = false;
        didCheck = true;

    }

    public void dontAllow() {
        Log.i("LICENSE", "dontAllow");
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        displayResult(getString(R.string.dont_allow));
        licensed = false;
        // 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.
        checkingLicense = false;
        didCheck = true;

        showDialog(0);
    }

    public void applicationError(int errorCode) {
        Log.i("LICENSE", "error: " + errorCode);
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        licensed = false;
        // 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.
        String result = String.format(
                getString(R.string.application_error), errorCode);
        checkingLicense = false;
        didCheck = true;

        displayResult(result);
        // showDialog(0);
    }

    public void allow(int reason) {
        // TODO Auto-generated method stub

    }

    public void dontAllow(int reason) {
        // TODO Auto-generated method stub

    }

}

protected Dialog onCreateDialog(int id) {
    // We have only one dialog.
    return new AlertDialog.Builder(this)
            .setTitle(R.string.unlicensed_dialog_title)
            .setMessage(R.string.unlicensed_dialog_body)
            .setPositiveButton(R.string.buy_button,
                    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);
                            finish();
                        }
                    })
            .setNegativeButton(R.string.quit_button,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int which) {
                            finish();
                        }
                    })

            .setCancelable(false)
            .setOnKeyListener(new DialogInterface.OnKeyListener() {
                public boolean onKey(DialogInterface dialogInterface,
                        int i, KeyEvent keyEvent) {
                    Log.i("License", "Key Listener");
                    finish();
                    return true;
                }
            }).create();

}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (mChecker != null) {
        Log.i("LIcense", "distroy checker");
        mChecker.onDestroy();
    }
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:30:25+00:00Added an answer on June 6, 2026 at 3:30 pm

    You are getting that error because you are trying to

     // Check the license
    LicenseCheckActivity  l = new LicenseCheckActivity();
    

    Instance an activity. You never do this! Always use the ActivityManager and Intents to start activities and pass information between them.

    The solution :

    Since you want your start class to continue extending Activity and cannot have it extend LicenseCheckActivity the only other suggestion would be to move the code in your start class.

    Ex:

    Take all the code from your LicenseCheckActivity and move it into your MainActivity class and then you can call checkLicense() in the onCreate method of your MainActivity

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i recently submitted an app and it's ready for sale now.But day by day
We have 2 big applications ready for app store submission but they were created
I have a sample app using CoreData, and am now ready to convert my
We have an app ready for submission to app store. The app is built
I have an iphone app ready and approved by the app store. Now I
We have our app all ready to upload to Apple for approval but have
I have a Wp7 app (ready in a xap), and I'd like to give
I have a Rails 3 app ready for staging. I haven't got a VPS
So I have my first app ready, and when I try to make my
I've recently submitted an application to the Mac App Store and have received an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.