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.