Myself recently in the course of learning Android, downloaded a demo altogether can't cancel Device Manager, nor uninstall. How do you think this is going to happen?
First Androidmanifest.xml:
XML code
- <receiver
- android:name="Com.dean.autosetting.DeviceMyReceiver"
- android:description="@string/description"
- Android:label="@string/app_name"
- 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" />
- <action android:name="Android.intent.action.BOOT_COMPLETED" />
-
- <category android:name="Android.intent.category.HOME" />
- </intent-filter>
- </receiver>
Devicemyreceiver.java
Java code
- Package com.dean.autosetting;
-
- import android.app.admin.DeviceAdminReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.util.Log;
- import android.widget.Toast;
-
- Public class Devicemyreceiver extends deviceadminreceiver {
-
- @Override
- Public void onreceive (context context, Intent Intent) {
- Super. OnReceive (context, intent);
- //Intent i = new Intent (context, mainactivity.class);
- //I.setflags (intent.flag_activity_new_task);
- //Context.startactivity (i);
- log.e ("autosetting", "receiver OnReceive");
- }
-
- /**
- * Get the value of device storage
- *
- * @param context
- * @return
- */
- Public static sharedpreferences getdevicepreference (context context) {
- return context.getsharedpreferences (devicemyreceiver. Class. GetName (), 0);
- }
-
- //Password features
- Public static String pref_password_quality = "Password_quality";
- //Length of password
- Public static String pref_password_length = "Password_length";
-
- Public static String PREF_MAX_FAILED_PW = "MAX_FAILED_PW";
-
- void showtoast (context context, charsequence text) {
- Toast.maketext (context, text, Toast.length_short). Show ();
- }
-
- @Override
- Public void onenabled (context context, Intent Intent) {
- showtoast (context, "Device Management: Available");
- }
-
- @Override
- Public void ondisabled (context context, Intent Intent) {
- showtoast (context, "Device Management: Not Available");
- }
-
- @Override
- Public charsequence ondisablerequested (context context, Intent Intent) {
- //The non-editable device is processed here.
- Intent intent2 = new Intent (context, noticesetting. Class);
- intent2.setflags (Intent.flag_activity_new_task);
- context.startactivity (Intent2);
- Context.stopservice (Intent); //Can stop
- return ""; //"This is an optional message that warns about the prohibition of user requests";
- }
-
- @Override
- Public void onpasswordchanged (context context, Intent Intent) {
- showtoast (context, "Device Management: Password has been changed");
- }
-
- @Override
- Public void onpasswordfailed (context context, Intent Intent) {
- showtoast (context, "Device Management: Change password failed");
- }
-
- @Override
- Public void onpasswordsucceeded (context context, Intent Intent) {
- showtoast (context, "Device Management: Change Password Success");
- }
-
- }
The core code is broken:
Java code
- @Override
- Public charsequence ondisablerequested (context context, Intent Intent) {
- //The non-editable device is processed here.
- Intent intent2 = new Intent (context, noticesetting. Class);
- intent2.setflags (Intent.flag_activity_new_task);
- context.startactivity (Intent2);
- Context.stopservice (Intent); //Can stop
- return ""; //"This is an optional message that warns about the prohibition of user requests";
- }
The core is a ondisablerequested method that can be manipulated. Normally, the user is prompted with a word when the check is unchecked. Here Context.stopservice (intent); I turned off the setup interface. And then jump to I set the Dead interface noticesetting. Noticesetting interface buttons do not work, only reboot.
PS: Just study, do not recommend you do rogue software. I myself also very conflicted. Learning, if you have questions welcome message, or version compatibility issues. Learn together. If you encounter such software, you can use more authoritative software uninstall, if not uninstall, you can root, directly to the app folder to delete the apk file.
Android Learning--Device Manager can no longer be canceled after it is checked