Hi all,
In this tutorial I will show you how to get the information about all the applications installed in your ANDROID phone.
What you have to do is create a ANDROID project inside the package pack.GetAllInstalledApplications amd name the java file “GetAllInstalledApplicationsExample.java” and copy the following code into it.

Here the “getPackageManager().getInstalledPackages(0);” gets information about all the packages installed in your ANDROID Phone or emulator.
Now go on and try this.

package pack.GetAllInstalledApplications;

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class GetAllInstalledApplicationsExample extends Activity {

	 public  ArrayList<packageInfoStruct> res = new ArrayList<packageInfoStruct>();
	 public ListView list;
	 public String app_labels[];

	 public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.main);

	        getPackages();

	        list = (ListView)findViewById(R.id.ListView01);
			try{
				list.setAdapter(new ArrayAdapter<string>(this,
					android.R.layout.simple_dropdown_item_1line, app_labels));
			}catch(Exception e){
				System.out.println("Err ++> " + e.getMessage());
				Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
			}

	 }
	private ArrayList<packageInfoStruct> getPackages() {
	    ArrayList<packageInfoStruct> apps = getInstalledApps(false);
	    final int max = apps.size();
	    for (int i=0; i < max; i++) {
	        apps.get(i);
	    }
	    return apps;
	}

	private ArrayList<packageInfoStruct> getInstalledApps(boolean getSysPackages) {

	    List<packageInfo> packs = getPackageManager().getInstalledPackages(0);
	    try{
	    	app_labels = new String[packs.size()];
	    }catch(Exception e){
			Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
		}
	    for(int i=0;i < packs.size();i++) {
	        PackageInfo p = packs.get(i);
	        if ((!getSysPackages) && (p.versionName == null)) {
	            continue ;
	        }
	        PackageInfoStruct newInfo = new PackageInfoStruct();
	        newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
	        newInfo.pname = p.packageName;
	        newInfo.versionName = p.versionName;
	        newInfo.versionCode = p.versionCode;
	        newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
	        res.add(newInfo);

	        app_labels[i] = newInfo.appname;
	    }
	    return res;
	}
}
/* This class is for storing the data for each application */
class PackageInfoStruct {
    String appname = "";
    String pname = "";
    String versionName = "";
    int versionCode = 0;
    Drawable icon;
}

The main.xml file

<?xml version="1.0" encoding="utf-8"?>
<linearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
 <listView android:id="@+id/ListView01"
  android:layout_height="375px"
  android:layout_width="fill_parent">
 </listView>
</linearLayout>

The manifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="pack.GetAllInstalledApplications"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".GetAllInstalledApplicationsExample"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
Get all installed applications in your ANDROID Phone

Showin all applications installed in your ANDROID Phone or emulator

You can download the source code from here.

 

11 Comments

  1. ghostged May 6, 2011 at 7:56 pm

    Thanks! And whether it is possible a source code of this project?

     
  2. Ekjyot August 8, 2011 at 3:37 pm

    this code is not working…
    giving exception Failed to find an AVD compatible with target ‘Google APIs’.

     
    • James August 8, 2011 at 7:43 pm

      Oh Ekjyot, Create an AVD with the Target as Google API in the Android AVD Manager. The AVD you currently using is not for Maps it is the normal Target.

       
      • Ekjyot August 9, 2011 at 12:46 pm

        But now it is giving me the exception Failure starting core services

         
  3. D2 August 8, 2011 at 3:53 pm

    The above given code dont work . I have spend 5 hrs on this code but all in vain. So my request to others dont waste your time in using this code ….

     
    • James August 8, 2011 at 7:49 pm

      @D2 :- No one has ever any complaints about this code. You might be doing something wrong in your code.

       
      • D2 August 9, 2011 at 12:52 pm

        I had copied your code and just pasted it but your code didnt worked and about 5 hrs i worked on this code but all in vain..

         
  4. Muhammad Mubashir August 12, 2011 at 4:19 pm

    Add permission:

     
    • espoir November 23, 2011 at 4:49 am

      hello,
      I have an Error in ” try{
      list.setAdapter(new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, app_labels));
      } ”
      Error: The constructor ArrayAdapter(GetAllInstalledApplicationsExample, int, String[]) is undefined
      how can I resolve it?

       
      • James November 23, 2011 at 10:07 pm

        Hey espoir : Check the link below to download the complete project.

         
  5. net whiz December 14, 2011 at 2:06 pm

    This was a perfect program for what I want but now i am trying to edit it so that it only displays the applications that needs internet permission.Anyone with a sugggestion of what i need to do?

     

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.