0

我正在开发一个企业应用程序,我需要从代码中自动启用设备管理。

使用java反射,我尝试调用“setActiveAdmin”,这是“android.app.admin.DevicePolicyManager”中的一个隐藏函数。我有一个 java.lang.securityexception。

日志猫:

01-24 17:07:58.390: W/System.err(1004): java.lang.SecurityException: Neither user 10080 nor current process has android.permission.BIND_DEVICE_ADMIN.
01-24 17:07:58.390: W/System.err(1004):     at android.os.Parcel.readException(Parcel.java:1321)
01-24 17:07:58.390: W/System.err(1004):     at android.os.Parcel.readException(Parcel.java:1275)
01-24 17:07:58.390: W/System.err(1004):     at android.app.admin.IDevicePolicyManager$Stub$Proxy.setActiveAdmin(IDevicePolicyManager.java:1507)
01-24 17:07:58.390: W/System.err(1004):     at com.marakana.android.devicepolicydemo.DemoDeviceAdminReceiver.onDisabled(DemoDeviceAdminReceiver.java:55)
01-24 17:07:58.390: W/System.err(1004):     at android.app.admin.DeviceAdminReceiver.onReceive(DeviceAdminReceiver.java:311)
01-24 17:07:58.390: W/System.err(1004):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:1901)
01-24 17:07:58.390: W/System.err(1004):     at android.app.ActivityThread.access$2400(ActivityThread.java:122)
01-24 17:07:58.390: W/System.err(1004):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1052)
01-24 17:07:58.390: W/System.err(1004):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 17:07:58.390: W/System.err(1004):     at android.os.Looper.loop(Looper.java:132)
01-24 17:07:58.390: W/System.err(1004):     at android.app.ActivityThread.main(ActivityThread.java:4025)
01-24 17:07:58.390: W/System.err(1004):     at java.lang.reflect.Method.invokeNative(Native Method)
01-24 17:07:58.390: W/System.err(1004):     at java.lang.reflect.Method.invoke(Method.java:491)
01-24 17:07:58.390: W/System.err(1004):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-24 17:07:58.390: W/System.err(1004):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-24 17:07:58.390: W/System.err(1004):     at dalvik.system.NativeStart.main(Native Method)

在我的清单文件中,我已授予“android.permission.BIND_DEVICE_ADMIN”权限。我仍然收到此错误。如何解决这个问题?

编辑:清单文件

<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" />

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Sample"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <receiver
        android:name=".DemoDeviceAdminReceiver"
        android:permission="android.permission.BIND_DEVICE_ADMIN" >
        <intent-filter>

            <!-- This action is required -->
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
        </intent-filter>


        <meta-data
            android:name="android.app.device_admin"
            android:resource="@xml/device_admin_sample" />
    </receiver>
</application>
4

1 回答 1

0

android.permission.BIND_DEVICE_ADMIN android:protectionLevel="signature" ,所以你的应用应该用系统签名进行签名,否则你的应用无法获取android.permission.BIND_DEVICE_ADMIN

于 2014-02-12T07:11:52.393 回答