Android error "Not granting permission"

I recently studied device administration APIs, and I found that neither my code nor the sample code on the Android development website were able to enable device administration.

Error at startup:

12-28 17:24:49.596: WARN/PackageManager(60): Not granting permission android.permission.BIND_DEVICE_ADMIN to package com.example (protectionLevel=2 flags=0x8446)

and then this when I try to enable admin:

12-28 17:27:22.426: WARN/DeviceAdminAdd(396): Unable to retrieve device policy ComponentInfo{com.example/com.example.Receiver}
org.xmlpull.v1.XmlPullParserException: No android.app.device_admin meta-data

I set all permissions in exactly the same way as the manifest requirements:

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

and device policies are also set in accordance with the requirements set forth in the API.

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

I made a mistake when getting permission or device administration is not available without additional code signing?   

+3
source share
2 answers

XML, <receiver /> . :

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

, :

  • device_admin.xml \res\xml. , , XML ?

  • @string : ?

android:label="@string/device_admin"
+1

Source: https://habr.com/ru/post/1782513/


All Articles