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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:55:13+00:00 2026-05-29T07:55:13+00:00

public final static void lockDevice() { try { if (devicePolicyManager.isAdminActive(adminComponent)) { devicePolicyManager.lockNow(); } }

  • 0
public final static void lockDevice()
    {
        try
        {
            if (devicePolicyManager.isAdminActive(adminComponent))
            {
                devicePolicyManager.lockNow();
            }
        }
        catch (final Exception ex)
        {
            ...
        }
    }

The above code does not throw any exception nor it locks the screen for motorola xoom tablets only. (Both Homeycomb and Icecream Sandwitch) The same code works perfectly on other Homeycomb and ICS tablets.

I googled, but did not get any solution. Any Ideas…..?

  • 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-29T07:55:14+00:00Added an answer on May 29, 2026 at 7:55 am

    Possible reasons for this problem

    1) I think there is some problem with receiver’s meta-data in your AndroidManifest.xml

    2) You haven’t added the correct class(extended with DeviceAdminReceiver) to either adminComponent OR to android:name property of receiver.

    After spending lot of time on this i have created the code.

    Code for main Activity

    public class LockerTest extends Activity {
        protected static final int REQUEST_ENABLE = 0;
        DevicePolicyManager devicePolicyManager;
        ComponentName adminComponent;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Button button = (Button) findViewById(R.id.btn);
            button.setOnClickListener(btnListener);
    
        }
    
        Button.OnClickListener btnListener = new Button.OnClickListener() {
            public void onClick(View v) {
                adminComponent = new ComponentName(LockerTest.this, Darclass.class);
                devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    
                if (!devicePolicyManager.isAdminActive(adminComponent)) {
    
                    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, adminComponent);
                    startActivityForResult(intent, REQUEST_ENABLE);
                } else {
                    devicePolicyManager.lockNow();
                }
    
            }
        };
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (REQUEST_ENABLE == requestCode) {
                super.onActivityResult(requestCode, resultCode, data);
            }
        }
    
    }
    

    Create a new class – Darclass – code

    import android.app.admin.DeviceAdminReceiver;
    
    public class Darclass extends DeviceAdminReceiver{
    
    }
    

    Create a folder ‘xml’ in ‘res’. Then create my_admin.xml file in ‘xml’ folder. Code for my_admin.xml. Note add this receiver after </activity> and before </application>

    <device-admin xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-policies>
            <limit-password />
            <watch-login />
            <reset-password />
            <force-lock />
            <wipe-data />
        </uses-policies>
    </device-admin>
    

    Finally add the receiver given bellow to your AndroidManifest.xml

    <receiver
                android:name=".Darclass"
                android:permission="android.permission.BIND_DEVICE_ADMIN" >
                <meta-data
                    android:name="android.app.device_admin"
                    android:resource="@xml/my_admin" />
    
                <intent-filter>
                    <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
                </intent-filter>
            </receiver>
    

    It should work on your device.

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

Sidebar

Related Questions

considering this example: public static void main(final String[] args) { final List<String> myList =
public class test { public static final int nThreads = 2; public static void
Lets assume following classes definition: public class A { public final static String SOME_VALUE;
Consider this case: public Class1 { public static final String ONE = ABC; public
I wrote two methods in class Util: public static final <T> T[] copy1(T[] source)
Say I have a class: public class R { public static final int _1st
I've seen examples like this: public class MaxSeconds { public static final int MAX_SECONDS
I have a String[] with values like so: public static final String[] VALUES =
I'm trying to get a real equivalent for Java's public static final in Scala
Is there a way to force classes in Java to have public static final

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.