Android Open Door The application example of the dog in the program lock _android

Source: Internet
Author: User

This article illustrates the application of the Android Open Door Dog in the program lock. Share to everyone for your reference, specific as follows:

Protected static final String TAG = "Watchdogservice";
Private Applockdao DAO;
Private list<string> Lockapps;
Private Activitymanager AM;
Private Intent lockappintent; @Override public IBinder onbind (Intent Intent) {return null;}/** the method called when the service was first invoked * * @Override public void Oncre
    Ate () {super.oncreate ();
    DAO = new Applockdao (this);
    Get the application you want to lock Lockapps = Dao.getallpackname ();
    am = (Activitymanager) getsystemservice (Activity_service);
    Lockappintent = new Intent (this,lockscreenactivity.class);
    Lockappintent.setflags (Intent.flag_activity_new_task); New Thread () {public void run () {while (true) {try {//Get the Enrollment//return of the currently running application
            Back to the task stack information in the system, TaskInfos has only one element, corresponding to the currently running application list<runningtaskinfo> TaskInfos = am.getrunningtasks (1);
            Runningtaskinfo currenttask = taskinfos.get (0); Gets the package name of the program that contains the activity that is visible to the current user String Packname = currentTask.topActivity.geTpackagename ();
            LOG.I (TAG, "the currently running package name:" +packname);
              if (Lockapps.contains (packname)) {//Lock Lockappintent.putextra ("Packname", packname);
            StartActivity (lockappintent);
          }else{//release} sleep (200);
          catch (Exception e) {e.printstacktrace ();
    }
        }
      };
}.start ();

 }

More interested readers of Android-related content can view this site: "Introduction to Android Development and advanced Course", "Android Communication Summary", "Android Basic Components Usage Summary", "Android View Summary", " Android Layout layout Tips and a summary of the use of Android controls

I hope this article will help you with the Android program.

Related Article

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.