To determine if a program is running, you must first get the list of running tasks,
First join the permissions <uses-permission android:name= "Android.permission.GET_TASKS"/>, otherwise there may be exception thrown.
Determine if the application is running activitymanager am = (activitymanager) context.getsystemservice (Context.activity_service); list<runningtaskinfo> list = Am.getrunningtasks (+); Boolean isapprunning = false; String my_pkg_name = "Com.cyberblue.iitag"; for (Runningtaskinfo info:list) {if (Info.topActivity.getPackageName (). Equals (my_pkg_name) | | info.baseActivity.getPackageName (). Equals (My_pkg_ NAME)) {Isapprunning = true;LOG.I (Tag,info.topactivity.getpackagename () + "info.baseActivity.getPackageName () =" + Info.baseActivity.getPackageName ());Break}}100 represents the maximum number of tasks taken, info.topactivity indicates that the current running Activity,info.baseactivity table system background has this process running, specifically to do how to judge the business needs to see itself. This class also has more ways to get the system running, memory usage, etc.
If Bluetooth is started, the operation is not to restart Bluetooth, or it will cause the application after the installation of Bluetooth can not be turned off if (isapprunning) {Bluetoothadapter mbluetoothadapter = Bluetoothadapter.getdefaultadapter ();if (!mbluetoothadapter.isenabled ()) {Enable () Turn on Bluetooth, this method turns on Bluetooth does not pop up promptMbluetoothadapter.enable ();}}/*** detects if a activityupdate is at the top of the current task's stack */public boolean istopactivy (String cmdName) {Activitymanager manager = (activi Tymanager) Context.getsystemservice (Activity_service); list<runningtaskinfo> Runningtaskinfos = manager.getrunningtasks (1); String cmpnametemp = null; if (null! = Runningtaskinfos) {cmpnametemp= (runningtaskinfos.get (0). topactivity). toString); LOG.E ("Cmpname", "Cmpname:" +cmpname); } if (null = = Cmpnametemp) return false; Return Cmpnametemp.equals (cmdName);}
/**get the launcher status Get the status of launcher */ private boolean islauncherrunnig (Context cont EXT) { Boolean result = False, & nbsp list<string> names = Getallthelauncher (); Activitymanager Mactivitymanager = (Activitymanager) Context.getsystemservice (Context.activity_service); list<activitymanager.runningappprocessinfo> applist = Mactivitymanager.getrunningappprocesses (); for (Runningappprocessinfo running:applist) { if (running.importance = = Runningappprocessinfo.importance_foreground) { for (int i = 0; i < Names.size (); i++) {&NBsp; if (Names.get (i). Equals (Running.processname)) { &NBSP ; result = true; &NBS P break; &NBS P } & nbsp } & nbsp return result; }
/** get all Launcher**/private list<string> Getallthelauncher () { list<string > names = null; Packagemanager PKGMGT = This.getpackagemanager (); Intent it = new Intent (intent.action_main); it.addcategory (intent.category_home); list<resolveinfo> RA =pkgmgt.queryintentactivities (it,0); if (ra.size ()! = 0) { names = new Ar Raylist<string> (); } for (int i=0;i< ra.size (); i++) &NBSP ; { String PackageName = ra.get (i). activityinfo.package Name; Names.add (PackageName); } &nbsP return names; }
================================================android related APIs for system internal state information: get Activitymanager:activitymanager Activitymanager = (Activitymanager) this.getsystemservice (Activity_service) What is this bit of information: Configurationinfo Configurationinfo = Activitymanager.getdeviceconfigurationinfo (); Get information about the state of the process memory: debug.memoryinfo[] Processmemoryinfo = Activitymanager.getprocessmemoryinfo (processids); Gets the service information currently running:list<runningserviceinfo> Runningserviceinfos = activitymanager.getrunningservices (MaxValue ); Gets the currently running task information:list<runningtaskinfo> Runningtaskinfos = Activitymanager.getrunningtasks (MaxValue); The topactivity of the Runningtaskinfos is that the active activity of the current task in the task queue returned by Getrunningtasks () is sorted according to the activity of these tasks, the more active the more forward. The first one is the currently active task
Android is running the program with the interface