Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

device policy administration errors with Android

I recently started exploring the android device policy administration APIs and have run into a bit of a wall. i'm having problems simply enabling the device administration. I'm fairly certain it is a problem with the manifest entry, however I can't quite pinpoint the problem area.

Manifest entry:

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

    <application android:label="DeviceAdminTrial" android:icon="@drawable/icon" android:debuggable="true">
        <activity android:name=".MyActivity"
                  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=".Receiver"
                  android:label="device_admin"
                  android:permission="android.permission.BIND_DEVICE_ADMIN"/>
                  <meta-data android:name="android.app.device_admin"
                             android:resource="@xml/device_admin"  />
                  <intent-filter>
                        <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
                  </intent-filter>
    </application>
</manifest> 

Error message:

12-25 15:42:38.930: WARN/DeviceAdminAdd(394): Unable to retrieve device policy ComponentInfo{com.example/com.example.Receiver}
        org.xmlpull.v1.XmlPullParserException: No android.app.device_admin meta-data

device_admin.xml

<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>

Enabling Method:

 enable = (Button)findViewById(R.id.button);
        enable.setOnClickListener(new View.OnClickListener()
        {
         public void onClick(View v)
         {
          Intent intent = new Intent (DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
          intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, receiver);

          startActivityForResult(intent, 1);//1 is enabled, 0 is disabled.
          output.setText(""+policymanager.isAdminActive(receiver));
         }
        });

And the Receiver class is as basic as the sample found here: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.html

any help or advice would be much appreciated.

like image 224
Jainathan Leung Avatar asked Dec 25 '10 21:12

Jainathan Leung


People also ask

How do I fix Device Policy Network Error?

Go to Settings > Applications > Google Drive. Here, tap on “Storage” and then tap on “Clear Data” to reset Google Drive data. This should fix “Network error, please try again later” error.

How do I bypass device administrator on Android?

Go to your phone's settings and then click on “Security.” You'll see “Device Administration” as a security category. Click on it to see a list of apps that have been given administrator privileges. Click the app you want to remove and confirm that you want to deactivate administrator privileges.


2 Answers

In manifest:

<receiver android:name=".Receiver"
        android:label="device_admin"
        android:permission="android.permission.BIND_DEVICE_ADMIN">
    <meta-data android:name="android.app.device_admin"
               android:resource="@xml/device_admin" />
    <intent-filter>
        <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
    </intent-filter>
</receiver>
like image 147
asif hasnain Avatar answered Oct 01 '22 08:10

asif hasnain


chk this out: http://rootfs.wordpress.com/2010/09/09/android-make-your-application-a-device-administrator/

like image 24
Syed Avatar answered Oct 01 '22 07:10

Syed