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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:58:16+00:00 2026-06-04T16:58:16+00:00

I am using the Device Policy Manager to lock the android phone immediately and

  • 0

I am using the Device Policy Manager to lock the android phone immediately and here is my activity code:

package com.husam.admin;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

public class AdminActivity extends Activity {

    /** Called when the activity is first created. */
    protected static final int REQUEST_CODE_ENABLE_ADMIN=1;
    DevicePolicyManager dpm;
    ComponentName mAdminName;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        dpm=(DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);   
        mAdminName=new ComponentName(this,MyAdmin.class);
        Button button=(Button)findViewById(R.id.admin);
        button.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {

                // TODO Auto-generated method stub
                if(dpm.isAdminActive(mAdminName))
                {
                    Log.w("Yes admin","Locking Now");
                    dpm.lockNow();  
                }
                else
                {Intent intent1 =new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                intent1.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
                intent1.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Need new Admin");
                Log.w("no Admin","Set admin");
                startActivityForResult(intent1,REQUEST_CODE_ENABLE_ADMIN);
                }

            }
        });

    }

     class MyAdmin extends DeviceAdminReceiver{

        void OnEnabled(){

        }
        void onDisable(){

        }
    }
} 

and My Mainfest.xml fill is as follow:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.husam.admin"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".AdminActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver 
            android:name=".MyAdmin"
            android:label="@string/device_admin"
            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>
    </application>

</manifest>

and my_admin.xml which is inside xml folder under res folder is as follows:

<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-policies>
        <force-lock />
    </uses-policies>
</device-admin>

and when I run my app I faced an error in my Log file state that:

W/DeviceAdminAdd(433): Unable to retrieve device policy ComponentInfo{com.husam.admin/com.husam.admin.AdminActivity$MyAdmin}

I searched this website for similar issued but all what I found is that the error was in the mainfest file in closing the receiver before including the meat and intent filter inside it which is not as my case.

So any help or redirection to solve this issue will be completely appreciated

regards

Husam

  • 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-04T16:58:17+00:00Added an answer on June 4, 2026 at 4:58 pm

    I think I figured out the answer to the question I posted above. What I need to do is that in registering my receiver in my mainfest file I have to do the following:

            <receiver 
                android:name=".AdminActivity$MyAdmin"
                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>
    

    Note:

    in android:name I have to write .AdminActivity$Myadmin instead of .Myadmin, since my class for administration broadcast receiver is an inner class in my activity, not a separate one.

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

Sidebar

Related Questions

I am trying to debug a C++ native code on Android device using NDK.
I need to lock my phone without using the device physical button. I created
I want to block given URLs of an Android device using JAVA code. When
I can drop a SqlServer Backup Device using SQL-DMO using the following pseudo-code: SQLDMO.SQLServer2
I'm trying to get the local IP address of my Android device using Mono
Here is the xml file of my Android widget: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
I'm using Mobile Device Browser File ( http://mdbf.codeplex.com/ ) for my ASP.NET MVC 2
How do I fully close a PhoneGap Android app? I've tried using device.exitApp() as
How to block installation of other application using device administrator app in android. How
I upload my app to app store, I already build my apps using device

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.