Android Task Manager (12 functions)

Source: Internet
Author: User

First of all, the source code is down from EOE, and the interface is slightly changed. The rest is basically not dynamic, and many codes are not named properly, let's take a look at the program running effect first,


When you click the corresponding icon, the corresponding list will appear, which will be attached below.


Here, we only list the functional code. You can study the detailed code by yourself:


Activitymanager AM = NULL; packagemanager PM = NULL; packageinfo info = NULL; activitymanager. memoryinfo = NULL; // Process List <runningappprocessinfo> processinfos = NULL; // list of installers <applicationinfo> applicationinfos = NULL; // task list <runningtaskinfo> taskinfos = NULL; List <runningserviceinfo> serviceinfos = NULL; listadapter adapter = NULL; AM = (activitymanager) getsystemservice (context. activity_service); PM = getapplicationcontext (). getpackagemanager (); PM. getinstalledpackages (0); processinfos = new arraylist <runningappprocessinfo> (); applicationinfos = new arraylist <applicationinfo> (); Info = new packageinfo (); memoryinfo = new activitymanager. memoryinfo (); listview = (listview) findviewbyid (R. id. list); memoryutil = new processmemoryutil (); memoryutil. initpmutil ();

Obtain the list of running processes:

Public void getrunningappprocessinfo () {processinfos = aM. getrunningappprocesses (); log. I ("getrunningappprocessinfo", "Total" + processinfos. size (); For (INT I = 0; I <processinfos. size (); I ++) {/* log. I ("getrunningappprocessinfo", processinfos. get (I ). processname + "," + processinfos. get (I ). PID); */} public list <Map <string, string> getrunningappprocessinfo1 () {list <Map <string, string> List = new arraylist <Map <string, string >>(); processinfos = aM. getrunningappprocesses (); Map <string, string> map = new hashmap <string, string> (); map. put ("process name", "Total" + processinfos. size () + "entries"); list. add (MAP); For (INT I = 0; I <processinfos. size (); I ++) {map = new hashmap <string, string> (); map. put ("process name", processinfos. get (I ). processname); map. put ("CPU", memoryutil. getmeminfobypid (processinfos. get (I ). PID); list. add (MAP);} return list ;}

Get the installer list:

Public void getapplicationinfolist () {applicationinfos = PM. getinstalledapplications (packagemanager. get_uninstalled_packages); // log. I ("getapplicationinfolist", "Total" + applicationinfos. size (); For (INT I = 0; I <applicationinfos. size (); I ++) {/* log. I ("getapplicationinfolist", applicationinfos. get (I ). packagename + "\ t" + applicationinfos. get (I ). processname); */} public list <Map <string, string> getapplicationinfolist1 () {list <Map <string, string> List = new arraylist <Map <string, string >>(); applicationinfos = PM. getinstalledapplications (packagemanager. get_uninstalled_packages); Map <string, string> map = new hashmap <string, string> (); map. put ("process name", "Total" + applicationinfos. size () + "entries"); list. add (MAP); For (INT I = 0; I <applicationinfos. size (); I ++) {map = new hashmap <string, string> (); map. put ("process name", applicationinfos. get (I ). processname); list. add (MAP);} return list ;}

Get package information:

Public void getpackageinfo () throws namenotfoundexception {// log. I ("getpackageinfo", "Total" + processinfos. size (); For (INT I = 0; I <processinfos. size (); I ++) {info = PM. getpackageinfo (processinfos. get (I ). processname, packagemanager. get_activities); // log. I ("getpackageinfo", info. packagename) ;}} public list <Map <string, string> getpackageinfo1 () {list <Map <string, string> List = new arraylist <Map <string, string >>(); For (INT I = 0; I <processinfos. size (); I ++) {Map <string, string> map = new hashmap <string, string> (); try {info = PM. getpackageinfo (processinfos. get (I ). processname, packagemanager. get_activities); map. put ("package name", info. packagename); list. add (MAP);} catch (namenotfoundexception e) {e. printstacktrace ();/* map. put ("package name", "null"); list. add (MAP); */} return list ;}

Obtain the Task Name and chart:

Public void getloadiconandlabel () {log. I ("getloadiconandlabel", "Total" + applicationinfos. size (); For (INT I = 0; I <applicationinfos. size (); I ++) {// log. I ("getloadiconandlabel", applicationinfos. get (I ). loadicon (PM ). tostring () + "," + applicationinfos. get (I ). loadlabel (PM ). tostring () ;}} public list <Map <string, string> getloadiconandlabel1 () {list <Map <string, string> List = new arraylist <Map <string, string >>(); Map <string, string> map = new hashmap <string, string> (); map. put ("process name", "Total" + applicationinfos. size () + "entries"); list. add (MAP); For (INT I = 0; I <applicationinfos. size (); I ++) {map = new hashmap <string, string> (); map. put ("image", applicationinfos. get (I ). loadicon (PM ). tostring (); map. put ("name", applicationinfos. get (I ). loadlabel (PM ). tostring (); list. add (MAP);} return list ;}

Obtain the available system memory size:

Public void getmemoryinfo () {Am. getmemoryinfo (memoryinfo); string memory = formatter. formatfilesize (getbasecontext (), memoryinfo. availmem); system. out. println ("memory =" + Memory);} public list <Map <string, string> getmemoryinfo1 () {list <Map <string, string> List = new arraylist <Map <string, string> (); Map <string, string> map = new hashmap <string, string> (); AM. getmemoryinfo (memoryinfo); string memory = formatter. formatfilesize (getbasecontext (), memoryinfo. availmem); map. put ("available memory", "available memory:" + Memory); list. add (MAP); return list ;}

Obtain the user-installed program:

@ Suppresswarnings ("static-access") Public void getuserapplication () {applicationinfos = PM. getinstalledapplications (packagemanager. get_uninstalled_packages); int COUNT = 0; For (INT I = 0; I <applicationinfos. size (); I ++) {If (applicationinfos. get (I ). flags & applicationinfos. get (I ). flag_system) <= 0) {count ++; // log. I ("getuserapplication", applicationinfos. get (I ). processname) ;}// log. I ("getuserapplication", "Total" + count) ;}@ suppresswarnings ("static-access") public list <Map <string, string> getuserapplication1 () {list <Map <string, string> List = new arraylist <Map <string, string> (); applicationinfos = PM. getinstalledapplications (packagemanager. get_uninstalled_packages); Map <string, string> map = NULL; For (INT I = 0; I <applicationinfos. size (); I ++) {If (applicationinfos. get (I ). flags & applicationinfos. get (I ). flag_system) <= 0) {map = new hashmap <string, string> (); map. put ("Installer", applicationinfos. get (I ). packagename); list. add (MAP) ;}}if (MAP = NULL) {map = new hashmap <string, string> (); map. put ("Installer", "NONE"); list. add (MAP);} return list ;}

Uninstall the program:

Public void uninstallapp (string getpackagename) {URI uri = Uri. fromparts ("package", getpackagename, null); intent it = new intent (intent. action_delete, Uri); If (it! = NULL) {startactivity (IT) ;}else {toast. maketext (this, "intent is null", 3000). Show ();}}

Task List:

Public list <Map <string, string> gettasks () {list <Map <string, string> List = new arraylist <Map <string, string> (); taskinfos = aM. getrunningtasks (30); // 30 indicates the maximum number obtained for (INT I = 0; I <taskinfos. size (); I ++) {Map <string, string> map = new hashmap <string, string> (); map. put ("task", taskinfos. get (I ). baseactivity. getclassname (); list. add (MAP);} return list ;}

Service list:

Public list <Map <string, string> getrunningserviceinfo () {list <Map <string, string> List = new arraylist <Map <string, string> (); stringbuffer serviceinfo = new stringbuffer (); serviceinfos = aM. getrunningservices (100); @ suppresswarnings ("UNUSED") string isrunning = ""; for (iterator <runningserviceinfo> it = serviceinfos. iterator (); it. hasnext ();) {runningserviceinfo Si = (runningserviceinfo) it. next (); If (SI. service. getclassname (). tostring (). equals ("com. android. controladdfunctions. phoneservice ") {isrunning =" running ";} else {isrunning =" not running ";} Map <string, string> map = new hashmap <string, string> (); map. put ("service class name", "service class name:" + Si. service. getclassname (); map. put ("process", "process:" + Si. process + "PID :(" + Si. PID + ")"); list. add (MAP); serviceinfo. append ("PID :"). append (SI. PID); serviceinfo. append ("\ nprocess :"). append (SI. process); serviceinfo. append ("\ nservice :"). append (SI. service); serviceinfo. append ("\ n");} log. I ("test", serviceinfo. tostring (); return list ;}

Exit the program and return to the home page:

private void returnToHome(){    Intent home=new Intent(Intent.ACTION_MAIN);    home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);    home.addCategory(Intent.CATEGORY_HOME);    startActivity(home);    }

Get current power:

Public list <Map <string, string> getcurrbattery () {list <Map <string, string> List = new arraylist <Map <string, string> (); map <string, string> map = new hashmap <string, string> (); battery = txt_battery.gettext (). tostring (); map. put ("power", battery); list. add (MAP); return list ;}


Finally: Success!




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.