List all app information in the system

Source: Internet
Author: User

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

Related Article

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.