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 8615409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:22:14+00:00 2026-06-12T05:22:14+00:00

I have an app that use the Google Liense Protection LVL to avoid the

  • 0

I have an app that use the Google Liense Protection LVL to avoid the access in case license fail I have set to disable buttonNewDoc if the license checking success I must re-enable this.

Unfortunately something doesn’t works.

This is my code:

    public class Home extends Activity {
        private static final String BASE64_PUBLIC_KEY = "mykeywithoutspaces";

        // Generate your own 20 random bytes, and put them here.
        private static final byte[] SALT = new byte[] {
            -00, 00, 30, -2, -58, -57, 00, -64, 51, 32, -95, -45, 13, -6, -36, -15, -11, 32, -64,
            89
        };

        private TextView mStatusText;
        private Button mCheckLicenseButton;

        private LicenseCheckerCallback mLicenseCheckerCallback;
        private LicenseChecker mChecker;
        // A handler on the UI thread.
        private Handler mHandler;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
            setContentView(R.layout.main);

            mStatusText = (TextView) findViewById(R.id.status_text);
buttonNewDoc = (ImageButton) findViewById(R.id.btNewDoc);
        buttonNewDoc.setOnClickListener(mNewDoc);
            mCheckLicenseButton = (Button) findViewById(R.id.check_license_button);
            mCheckLicenseButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    doCheck();
                }
            });

            mHandler = new Handler();

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

        protected Dialog onCreateDialog(int id) {
            final boolean bRetry = id == 1;
            return new AlertDialog.Builder(this)
                .setTitle(R.string.unlicensed_dialog_title)
                .setMessage(bRetry ? R.string.unlicensed_dialog_retry_body : R.string.unlicensed_dialog_body)
                .setPositiveButton(bRetry ? R.string.retry_button : R.string.buy_button, new DialogInterface.OnClickListener() {
                    boolean mRetry = bRetry;
                    public void onClick(DialogInterface dialog, int which) {
                        if ( mRetry ) {
                            doCheck();
                        } else {
                            Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                    "http://market.android.com/details?id=" + getPackageName()));
                                startActivity(marketIntent);                        
                        }
                    }
                })
                .setNegativeButton(R.string.quit_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).create();
        }

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

        private void displayResult(final String result) {
            mHandler.post(new Runnable() {
                public void run() {
                    mStatusText.setText(result);
                    setProgressBarIndeterminateVisibility(false);
                    mCheckLicenseButton.setEnabled(true);
                }
            });
        }

        private void displayDialog(final boolean showRetry) {
            mHandler.post(new Runnable() {
                public void run() {
                    setProgressBarIndeterminateVisibility(false);
                    showDialog(showRetry ? 1 : 0);
                    mCheckLicenseButton.setEnabled(true);
                }
            });
        }    

        private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
            public void allow(int policyReason) {
                if (isFinishing()) {
                    // Don't update UI if Activity is finishing.
                    return;
                }

                // Should allow user access.
                displayResult(getString(R.string.allow));
buttonNewDoc.setEnabled(false);
            }

            public void dontAllow(int policyReason) {
                if (isFinishing()) {
                    // Don't update UI if Activity is finishing.
                    return;
                }
                displayResult(getString(R.string.dont_allow));
                // 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.
                // If the reason for the lack of license is that the service is
                // unavailable or there is another problem, we display a
                // retry button on the dialog and a different message.
                displayDialog(policyReason == Policy.RETRY);
            }

            public void applicationError(int errorCode) {
                if (isFinishing()) {
                    // Don't update UI if Activity is finishing.
                    return;
                }
                String result = String.format(getString(R.string.application_error), errorCode);
                displayResult(result);
            }
        }

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

    }

And this is the Error:

10-03 14:23:01.469: E/AndroidRuntime(3457): FATAL EXCEPTION: background thread
10-03 14:23:01.469: E/AndroidRuntime(3457): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
10-03 14:23:01.469: E/AndroidRuntime(3457):     at android.view.ViewRoot.checkThread(ViewRoot.java:3020)
10-03 14:23:01.469: E/AndroidRuntime(3457):     at android.view.ViewRoot.invalidateChild(ViewRoot.java:647)
10-03 14:23:01.469: E/AndroidRuntime(3457):     at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:673)
10-03 14:23:01.469: E/AndroidRuntime(3457):     at android.view.ViewGroup.invalidateChild(ViewGroup.java:2511)
10-03 14:23:01.469: E/AndroidRuntime(3457):     at android.view.View.invalidate(View.java:5279)
10-03 14:23:01.469: E/AndroidRuntime(3457):     at android.view.View.setEnabled(View.java:3151)
10-03 14:23:01.469: E/AndroidRuntime(3457):     at com.myapp.Home$MyLicenseCheckerCallback.allow(Home.java:143)
  • 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-12T05:22:16+00:00Added an answer on June 12, 2026 at 5:22 am

    Instead of mHandler.post, try runOnUiThread for the Runnable objects that need to alter UI components.

    Update: The below line of code is what’s causing your problem

    public void allow(int policyReason) {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
    
        // Should allow user access.
        displayResult(getString(R.string.allow));
        buttonNewDoc.setEnabled(false); /* This is the problem line */
    }
    

    That statement needs to happen on the UI thread which isn’t happening right now. Making that statement run on the UI thread should fix your problem.

    public void allow(int policyReason) {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
    
        // Should allow user access.
        displayResult(getString(R.string.allow));
        runOnUiThread(new Runnable() {
            public void run() {
                buttonNewDoc.setEnabled(false);
            }
        });
    }
    

    You should really rework things so that all UI altering statements are on the main UI thread but this should at least fix your problem.

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

Sidebar

Related Questions

Quick question. I have an app that use a native DLL through PInvoke, this
I have a Django app that use a django-tagging. I need to port this
I have a console command line app that use NHibernate . I am trying
I have an app that needs to be able use either an sqlite3 datebase
I have a small helper app that I use to inject scripts into html
I have an app that is minSDK 10, target's 14. I'd love to use
Previously, I have an app that uses core data. I use same store url
We have a web app that we update and release almost daily. We use
I have an In-house windows form app that I would like to use Spell
I have a custom animaiton that I use thru 90% of my app. I

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.