Obtain information about installed apps on android devices.

Source: Internet
Author: User

Obtain information about installed apps on android devices.

This article describes how to obtain information about installed applications on a device, including the Application name, package name, and icon.

After obtaining the information list, you can select a record to start the corresponding application!

 

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; public class AppListFragment extends ListFragment {private ArrayList appList = new ArrayList (); @ 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);}/*** obtain the list of non-system application information */private void getAppList () {PackageManager pm = this. getActivity (). getPackageManager (); // Return a List of all packages that are installed on the device. list
 
  
Packages = pm. getInstalledPackages (0); for (PackageInfo packageInfo: packages) {// determine the 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 Intent of the application installation package, which is used to start the application info. appIntent = pm. getLaunchIntentForPackage (packageInfo. packageName); appList. add (info) ;}else {// System Application }}}}
 

 

 

The getAppList () method obtains the application information installed on the current device.

Use the following code to determine whether an application is a system application or a non-system application:

 

// Determine the system/non-system application if (packageInfo. applicationInfo. flags & ApplicationInfo. FLAG_SYSTEM) = 0) // non-system application {} else {// System Application}

Use the following code to obtain the Intent required to start another application:

 

 

// Obtain the Intent of the application installation package to start the application info. appIntent = pm. getLaunchIntentForPackage (packageInfo. packageName );

 

 

 

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.