Android Learning--Device Manager can no longer be canceled after it is checked

Source: Internet
Author: User

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
  1. <receiver
  2. android:name="Com.dean.autosetting.DeviceMyReceiver"
  3. android:description="@string/description"
  4. Android:label="@string/app_name"
  5. android:permission="Android.permission.BIND_DEVICE_ADMIN" >
  6. <Meta-data
  7. android:name="Android.app.device_admin"
  8. Android:resource="@xml/device_admin" />
  9.   
  10. <intent-filter>
  11. <action android:name="Android.app.action.DEVICE_ADMIN_ENABLED" />
  12. <action android:name="Android.intent.action.BOOT_COMPLETED" />
  13.   
  14. <category android:name="Android.intent.category.HOME" />
  15. </intent-filter>
  16. </receiver>

Devicemyreceiver.java

Java code
  1. Package com.dean.autosetting;
  2.   
  3. import android.app.admin.DeviceAdminReceiver;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.SharedPreferences;
  7. import android.util.Log;
  8. import android.widget.Toast;
  9.   
  10. Public class Devicemyreceiver extends deviceadminreceiver {
  11.   
  12. @Override
  13. Public void onreceive (context context, Intent Intent) {
  14. Super. OnReceive (context, intent);
  15. //Intent i = new Intent (context, mainactivity.class);
  16. //I.setflags (intent.flag_activity_new_task);
  17. //Context.startactivity (i);
  18. log.e ("autosetting", "receiver OnReceive");
  19.     }  
  20.   
  21.     /** 
  22. * Get the value of device storage
  23.      *  
  24. * @param context
  25. * @return
  26.      */  
  27. Public static sharedpreferences getdevicepreference (context context) {
  28. return context.getsharedpreferences (devicemyreceiver.   Class. GetName (), 0);
  29.     }  
  30.   
  31. //Password features
  32. Public static String pref_password_quality = "Password_quality";
  33. //Length of password
  34. Public static String pref_password_length = "Password_length";
  35.   
  36. Public static String PREF_MAX_FAILED_PW = "MAX_FAILED_PW";
  37.   
  38. void showtoast (context context, charsequence text) {
  39. Toast.maketext (context, text, Toast.length_short). Show ();
  40.     }  
  41.   
  42. @Override
  43. Public void onenabled (context context, Intent Intent) {
  44. showtoast (context, "Device Management: Available");
  45.     }  
  46.   
  47. @Override
  48. Public void ondisabled (context context, Intent Intent) {
  49. showtoast (context, "Device Management: Not Available");
  50.     }  
  51.   
  52. @Override
  53. Public charsequence ondisablerequested (context context, Intent Intent) {
  54. //The non-editable device is processed here.   
  55. Intent intent2 = new Intent (context, noticesetting.   Class);
  56. intent2.setflags (Intent.flag_activity_new_task);
  57. context.startactivity (Intent2);
  58. Context.stopservice (Intent); //Can stop
  59. return "";  //"This is an optional message that warns about the prohibition of user requests";
  60.     }  
  61.   
  62. @Override
  63. Public void onpasswordchanged (context context, Intent Intent) {
  64. showtoast (context, "Device Management: Password has been changed");
  65.     }  
  66.   
  67. @Override
  68. Public void onpasswordfailed (context context, Intent Intent) {
  69. showtoast (context, "Device Management: Change password failed");
  70.     }  
  71.   
  72. @Override
  73. Public void onpasswordsucceeded (context context, Intent Intent) {
  74. showtoast (context, "Device Management: Change Password Success");
  75.     }  
  76.   
  77. }  

The core code is broken:

Java code
  1. @Override
  2. Public charsequence ondisablerequested (context context, Intent Intent) {
  3. //The non-editable device is processed here.   
  4. Intent intent2 = new Intent (context, noticesetting.   Class);
  5. intent2.setflags (Intent.flag_activity_new_task);
  6. context.startactivity (Intent2);
  7. Context.stopservice (Intent); //Can stop
  8. return "";  //"This is an optional message that warns about the prohibition of user requests";
  9.     }  

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.