Get app info for Android device installed

Source: Internet
Author: User

This article describes how to get app information that's already installed on your device, including: App Name, package name, icon, and so on.

Once you have a list of information, you can also launch the corresponding app by selecting a record!



1. Code implementation

Package Com.example.showapplist;import Java.util.arraylist;import Java.util.list;import Android.content.pm.applicationinfo;import Android.content.pm.packageinfo;import Android.content.pm.packagemanager;import Android.os.bundle;import Android.support.v4.app.listfragment;import Android.view.layoutinflater;import Android.view.view;import Android.view.viewgroup;import Android.widget.ListView ;p ublic class Applistfragment extends Listfragment {private arraylist<appinfo> applist = new arraylist<appinfo& gt; (); @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Getapplist (); Appadapter adapter = new Appadapter (this.getactivity (), applist); Setlistadapter (adapter);} @Overridepublic View Oncreateview (layoutinflater inflater, ViewGroup container,bundle savedinstancestate) {return Super.oncreateview (Inflater, container, savedinstancestate);} @Overridepublic void Onlistitemclick (ListView l, View v, int position, long ID) {//Start the selected application StartActivity (aPplist.get (position). Appintent);}  /** * Get non-system app information list */private void Getapplist () {Packagemanager pm = this.getactivity (). Getpackagemanager ();//Return a list Of all packages that is installed on the device. list<packageinfo> packages = pm.getinstalledpackages (0); for (PackageInfo packageinfo:packages) {//Judgment System/Non-system application if ((PackageInfo.applicationInfo.flags & applicationinfo.flag_system) = = 0)//non-system Application {AppInfo info = new AppInfo (); Info.appname = PackageInfo.applicationInfo.loadLabel (PM). toString (); info.pkgname = Packageinfo.packagename; Info.appicon = PackageInfo.applicationInfo.loadIcon (PM);//Gets the app installation package intent, which is used to launch the app info.appintent = Pm.getlaunchintentforpackage (Packageinfo.packagename); Applist.add (info);} else {//System Application}}}}


Among them, the Getapplist () method obtains the application information installed by the current device.

Determine whether an application is a system application or a non-system application using the following code:

Judging System/Non-system applications if ((PackageInfo.applicationInfo.flags & applicationinfo.flag_system) = = 0)//non-system application {} else {//System Application }

Get the intent you need to start another application by using the following code:


2. Project Source

http://download.csdn.net/detail/chadeltu/8554415


Get app info for Android device installed

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.