1 回答

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個贊
我找到了解決該問題的解決方法。我創(chuàng)建了一個用于設(shè)備關(guān)閉的廣播接收器,并在設(shè)備重新啟動時刪除限制并重新啟用限制。
public class ShutDownReceiver extends BroadcastReceiver {
private static final String TAG = "ShutDownReceiver";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_SHUTDOWN.equals(action)){
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName cn = AdminReceiver.getComponentName(context);
if (dpm != null && dpm.isDeviceOwnerApp(context.getPackageName())) {
//This is a custom method
setUserRestriction(dpm, cn, UserManager.DISALLOW_USB_FILE_TRANSFER, false);
}
Toast.makeText(context, "Shutting Down", Toast.LENGTH_SHORT).show();
Log.d(TAG, "onReceive: ACTION_SHUTDOWN");
}
}
}
在清單中添加代碼
<receiver android:name=".receiver.ShutDownReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
</intent-filter>
</receiver>
添加回答
舉報