Program run:
Program code:
/** * Get all software information * 1. Display all software in the system in an asynchronous manner * 2. Click to open the specified software * 3. Local sharedpreferences * To save the package name and activity name of all software * @author JPH * date:2014.09 . */public class ScanPackage1 extends Activity {/** Scan succeeded **/private final static int flag_load_success=0x10001;private fi nal static int scanning=0x10002;private ListView list;private list<map<string, Object>>items=new ArrayList <Map<String,Object>> ();p rivate simpleadapter adapter;//obtain all installation software information private list<packageinfo> allpackageinfos;//Obtain the software information installed by the private list<packageinfo> userpackageinfos;//obtain the software information of the system installation private list< Packageinfo> Syspackageinfos; Handler mhandler=new Handler () {@Overridepublic void Handlemessage (Message msg) {//TODO auto-generated method Stubswitch (msg.what) {case flag_load_success://complete scan break;case scanning://is scanning items.add ((map<string, object>) msg.obj); /Notification Adapter Data Change adapter.notifydatasetchanged (); break;default:break;}}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (SavedinstanCestate); Setcontentview (r.layout.sp_layout); list= (ListView) Findviewbyid (r.id.list); new Scanthread (). Start (); Adapter=new Simpleadapter (this, items, r.layout.line, new string[]{"Imgico", "AppName", "PackageName"}, New int[]{ R.ID.IMGICO,R.ID.TVAPPNAME,R.ID.TVAPPDESC}); List.setadapter (adapter);//viewbinder This class can help simpleadapter load pictures ( such as: bitmap,drawable) Adapter.setviewbinder (new Viewbinder () {@Overridepublic Boolean setviewvalue (view view, Object data , String textrepresentation) {//TODO auto-generated Method stub if (view instanceof ImageView && data instanceof D rawable) {ImageView IV = (ImageView) view; Iv.setimagedrawable ((drawable) data); return true; }else{return false; }}); List.setonitemclicklistener (new Onitemclicklistener () {@Overridepublic void Onitemclick (adapterview<?> arg0, View arg1, int arg2,long arg3) {//TODO auto-generated method stubtry {PackageInfo pinfo=allpackageInfos.get (arg2); Intent intent=new Intent (); Intent.setcomponent (New ComponentName (Pinfo.packagename, Pinfo.activities[0].name)); StartActivity (intent);} catch (Exception e) {//Todo:handle exceptione.printstacktrace ();}});} --------* Create a line loads-mount Installer *--------------*******************//private class Scanthread extends Thread { @Overridepublic void Run () {//Get system Install all software information Allpackageinfos = Getpackagemanager (). Getinstalledpackages ( packagemanager.get_uninstalled_packages| packagemanager.get_activities);//define User installation software information Package Userpackageinfos = new arraylist<packageinfo> ();// Define the system installation software information Package Syspackageinfos = new arraylist<packageinfo> ();//loop out all software information for (int i = 0; i < allpackageinfos.size ( ); i++) {//Get each software information PackageInfo temp = allpackageinfos.get (i); ApplicationInfo AppInfo = Temp.applicationinfo;if ((appinfo.flags & applicationinfo.flag_updated_system_app)! = 0| | (Appinfo.flags & applicationinfo.flag_system)! = 0) {//System software Syspackageinfos.add (temp);} else {//users install software themselves userpaCkageinfos.add (temp);} Gets the program's icon drawable Ico=scanpackage1.this.getpackagemanager (). Getapplicationicon (AppInfo);//Gets the name of the program string appname= (String) ScanPackage1.this.getPackageManager (). Getapplicationlabel (AppInfo); Map<string, Object>item=new hashmap<string, object> ();//Gets the package name of the program String Packagename=appinfo.packagename; Item.put ("Imgico", ico), Item.put ("AppName", AppName); Item.put ("PackageName", PackageName); Message message = new Message (); Message.what =scanning; Message.obj = Item; Mhandler.sendmessage (message);} Saveinfo (Syspackageinfos, Userpackageinfos); Mhandler.sendemptymessage (flag_load_success);}};/ * * To write information about the program installed in the system to the configuration file * @param syspackageinfos system installation Software information Package * @param userpackageinfos User install software packet */private void Saveinfo (Lis T<packageinfo> syspackageinfos,list<packageinfo> Userpackageinfos) {// Add user-installed software to the collection that is added to the system software Syspackageinfos.addall (USERPACKAGEINFOS); Sharedpreferences sp = this.getsharedpreferences ("Appinfs", Mode_privatE); Editor editor = Sp.edit (); for (int i = 0; i < syspackageinfos.size (); i++) {try {//Get the package name of the program string packagename = Syspacka Geinfos.get (i). packagename;//Remove activity information activityinfo Activityinfo = Syspackageinfos.get (i). activities[0];// Remove the activity name string activityname=activityinfo.name;//write the program information to the configuration file editor.putstring (PackageName, activityname);} catch (Exception e) {//Todo:handle exceptione.printstacktrace ();}} Editor.commit ();}}
Android Development to get all the software information