有了Android 6,我想設置的全局設置WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN
,這是我做了什麼:的Android 6,設置全局設置WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN
mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
deviceAdminComponentName = new ComponentName(this, MyDeviceAdminReceiver.class);
try {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,deviceAdminComponentName);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,"Your boss told you to do this");
startActivityForResult(intent, ACTIVATION_REQUEST);
}catch (Exception e){
Logg.d("Error: " + e.getMessage());
}
其中MyDeviceAdminReceiver是擴展DeviceAdminReceiver類。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ACTIVATION_REQUEST:
if (resultCode == Activity.RESULT_OK) {
try {
mDevicePolicyManager.setGlobalSetting(deviceAdminComponentName, Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, "1");
}catch (Exception e){
Logg.e("Error " + e.getMessage());
}
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
<receiver android:name=".MyDeviceAdminReceiver" android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/device_admin_sample" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
<expire-password />
<encrypted-storage />
<disable-camera />
<set-global-proxy/>
<disable-keyguard-features/>
</uses-policies>
</device-admin>
不幸的是,執行mDevicePolicyManager.setGlobalSetting
java.lang.SecurityException: Admin ComponentInfo{com..../com....MyDeviceAdminReceiver} does not own the device
at android.os.Parcel.readException(Parcel.java:1627)
at android.os.Parcel.readException(Parcel.java:1579)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.setGlobalSetting(IDevicePolicyManager.java:7150)
at android.app.admin.DevicePolicyManager.setGlobalSetting(DevicePolicyManager.java:4558)
at ....WifiScanActivity.onActivityResult(WifiScanActivity.java:152)
at android.app.Activity.dispatchActivityResult(Activity.java:6490)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3794)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3841)
at android.app.ActivityThread.access$1400(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1440)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:5526)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
任何想法時運行前面的代碼中,我總是得到一個安全異常是什麼時候?