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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:03:55+00:00 2026-05-21T18:03:55+00:00

I want to use some DevicePolicyManager methods in my app. The DevicePolicyManager was introduced

  • 0

I want to use some DevicePolicyManager methods in my app. The DevicePolicyManager was introduced in OS 2.2, but my app must continue to run on OS 2.1 devices.

Here’s pseudocode for what I want to do:

if (needSecurity)
{
  if (runningOS2.2orGreater) 
  {
    // Invoke the required security policy, e.g.
    setPasswordQuality(myComponentName, PASSWORD_QUALITY_NUMERIC)
  }
  else
  {
    // Tell the user they can't use this feature
  }
}

From reading the docs I think I may also need a DeviceAdminReceiver to handle onPasswordFailed and onPasswordSucceeded callbacks.

From other Stackoverflow questions (e.g. here), I believe I have two options:

1. Reflection

Continue to build against OS 2.1 SDK and use reflection to invoke classes at runtime, e.g.

Class myClass =                                                                        
  ClassLoader.getSystemClassLoader().loadClass("android.app.admin.DevicePolicyManager")

Object DPMInstance = myClass.newInstance();                                            

Method myMethod = myClass.getMethod("setPasswordQuality",                              
                                    new Class[] { ComponentName.class,                 
                                                  int.class });                        
myMethod.invoke(DPMInstance,                                                           
                new Object[] { myComponentName,                                        
                               PASSWORD_QUALITY_NUMERIC });                            

If I need to implement a DeviceAdminReceiver, will reflection work? How would I handle callbacks to DeviceAdminReceiver and call back into my own application classes?

2. Conditional class loading

Change to build against the OS 2.2 SDK. At runtime only load the OS 2.2 classes if the current device version is OS 2.2 or newer, e.g.

int sdk = new Integer(Build.VERSION.SDK).intValue();

if (sdk > 7) 
{
  sLog.info("OS 2.2 or later");
  return new myClassImplementsDeviceAdminInterfaces();
}
else
{
  sLog.info("OS 2.1 or earlier");
  return new myClassDoesNotSupportDeviceAdmin();
}

This approach looks like it will produce easier code to support, and presumably will work with a DeviceAdminReceiver too. Is anybody aware of any drawbacks or complications to it?

So, my questions are:

  • Would you recommend reflection or conditional class loading for using DevicePolicyManager?
  • Will I need a DeviceAdminReceiver, or can I detect whether the user has a suitable password, e.g. by repeatedly calling isActivePasswordSufficient in my app to confirm it has been done?
  • Any other tips if you have them (e.g. this question suggests there might be issues forcing the user to reset their password).

Thanks!

  • 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-05-21T18:03:56+00:00Added an answer on May 21, 2026 at 6:03 pm

    If I need to implement a DeviceAdminReceiver, will reflection work?

    Not really. You’d need to use conditional class loading, which means you may as well just go that route to begin with.

    Is anybody aware of any drawbacks or complications to it?

    Speaking on behalf of my little corner of “anybody”, I’m not aware of any drawbacks. I’d use the VERSION_CODES constants on Build, though, rather than the integer (7). And, unless you’re supporting 1.5, you can use SDK_INT on Build rather than SDK.

    Would you recommend reflection or conditional class loading for using DevicePolicyManager?

    Conditional class loading.

    Will I need a DeviceAdminReceiver, or can I detect whether the user has a suitable password, e.g. by repeatedly calling isActivePasswordSufficient in my app to confirm it has been done?

    That I can’t answer. If you don’t get another answer addressing this point, you might consider asking that in its own SO question.

    Any other tips if you have them

    Never get involved in a land war in Asia.

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

Sidebar

Related Questions

I want to use some C++ STL collections in my Objective-C iPhone app. Apparently
I want to use some of Google Guava methods and classes in my client-side
I want to use some Haskell libraries (e.g. Darcs, Pandoc) from Python, but it
I want to use some css framework but hate its unsemanticness. So I want
Hi have some forms that I want to use some basic php validation (regular
I want to use Powershell to write some utilities, leveraging our own .NET components
I want to use javascript to insert some elements into the current page. Such
Say I'm writing some ruby code and I want to use the standard Date
I use Lucene.Net to index some documents. I want to show the user a
I want to use the MultipleLookupField control in a web page that will run

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.