List all the app programs in the system, such as. Not much to say, directly on the code, very simple a small program.
Layout file Code:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " > <gridview android:id= "@+id/apps_list" android:layout_width= "Wrap_content" android: layout_height= "Wrap_content" android:numcolumns= "4" > </GridView> </ Relativelayout>
Mainactivity Code:
/** * Lists all apps in the system. * @author Lu Guoqiang. * */public class Mainactivity extends Actionbaractivity {//system all app information private list<resolveinfo> apps;//with nine Gongge view rendered Now all appprivate GridView apps_list; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Apps_list = (GridView) Findviewbyid (r.id.apps_list); Loadapps (); } private void Loadapps () {//Get system all app info Intent mainintent = new Intent (intent.action_main, NULL); Mainintent.addcategory (Intent.category_launcher); New ImageView (Mainactivity.this); Apps = Getpackagemanager (). Queryintentactivities (mainintent, 0); Set the information to the adapter Apps_list.setadapter (new Appsadapter ()); } public class Appsadapter extends Baseadapter {public appsadapter () {} @Overrid e public int GetCount () {return apps.size (); } @Override public Object getItem (int i) {return apps.get (i); } @Override public long getitemid (int i) {return i; } @Override public View getView (int i, view view, ViewGroup ViewGroup) {ImageView IV; if (view = = null) {IV = new ImageView (mainactivity.this); Iv.setscaletype (ImageView.ScaleType.FIT_CENTER); Iv.setlayoutparams (New Gridview.layoutparams (50, 50)); } else {IV = (ImageView) view; } ResolveInfo info = Apps.get (i); Iv.setimagedrawable (Info.activityInfo.loadIcon (Getpackagemanager ())); return IV; } } }
The configuration manifest file does not need to be modified.
List all app information in the system