I use Device Policy Manager to immediately block my Android phone, 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 { 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) {
and My Mainfest.xml is populated as follows:
<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 the xml folder under the res folder, looks like this:
<device-admin xmlns:android="http://schemas.android.com/apk/res/android"> <uses-policies> <force-lock /> </uses-policies> </device-admin>
and when I started the application, I encountered an error in my state of the log file, which:
W/DeviceAdminAdd(433): Unable to retrieve device policy ComponentInfo{com.husam.admin/com.husam.admin.AdminActivity$MyAdmin}
I searched this site for similar releases, but all I found was that there was an error in the mainfest file when closing the receiver, before including the meat and intent filter in it, which is not my case.
Therefore, any help or redirection to solve this problem will be fully appreciated.
considers
Khusy
source share