Tyler Meade
Tyler Meade

Reputation: 45

Need help getting a list of all apps installed on android phone

I am developing an application that needs a list of the apps that the user has installed on his phone. I have looked at ever tutorial online and none of them are specific enough, i.e. that show the code but never show where to put it

But being so new to programming I cannot use this because I do not know where to put it in my code, although I have found one code that works it does not show the version or the icon. I could really use someone to hold my hand on this one.

What I need specifically is an arraylist that shows the users installed apps, the icon, and the version.

Here is the code that I have working:

package com.fina;

    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 scan extends Activity {

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

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

              getPackages();

      list = (ListView)findViewById(R.id.listView1);
              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 getPackages() { ArrayList apps = getInstalledApps(false); final int max = apps.size(); for (int i=0; i < max; i++) { apps.get(i); } return apps; }

private ArrayList 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;
    }

And here is my allc.xml that links to it:

<AbsoluteLayout
    android:id="@+id/absoluteLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/allcast"
        android:layout_width="61dp"
        android:layout_height="66dp"
        android:layout_x="0dp"
        android:layout_y="0dp"
        android:background="@drawable/invis"
        />


    <Button
        android:id="@+id/downcast"
        android:layout_width="63dp"
        android:layout_height="60dp"
        android:layout_x="64dp"
        android:layout_y="3dp"
        android:background="@drawable/invis"
         />

    <Button
        android:id="@+id/commcast"
        android:layout_width="51dp"
        android:layout_height="57dp"
        android:layout_x="255dp"
        android:layout_y="3dp"
        android:background="@drawable/invis" />



    <Button
        android:id="@+id/achcast"
        android:layout_width="62dp"
        android:layout_height="58dp"
        android:layout_x="192dp"
        android:layout_y="2dp"
        android:background="@drawable/invis"
         />


    <Button
        android:id="@+id/recocast"
        android:layout_width="59dp"
        android:layout_height="60dp"
        android:layout_x="128dp"
        android:layout_y="3dp"
        android:background="@drawable/invis" />


    <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_x="0dp"
        android:layout_y="71dp" >

    </ListView>

</AbsoluteLayout>

Please be as specific as possible with your answers, not just a link to a website with a code I could use, I really need someone to hold my hand on this one.

Upvotes: 3

Views: 3482

Answers (1)

Pete Houston
Pete Houston

Reputation: 15079

On my tutorial, step-by-step instructions, and provide full source-code: https://xjaphx.wordpress.com/2011/06/12/create-application-launcher-as-a-list

Upvotes: 1

Related Questions