Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all apps installed on android phone

This is the code that i have at the moment but i still can't get a list of all the apps on the phone. Does anyone see what i am doing wrong?

public class GetAppList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try {
            List<PackageInfo> appListInfo1 = this.getPackageManager()
            .getInstalledPackages(0);
            JSONArray ja = new JSONArray();
            try {
                HttpClient httpclient = new DefaultHttpClient();
                Object sendDataUrl = null;
                HttpPost request = new HttpPost(sendDataUrl.toString());
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                ContextWrapper context = null;
                PackageManager pm = context.getPackageManager();
                List<PackageInfo> appListInfo = pm.getInstalledPackages(0);
                for (PackageInfo p : appListInfo) {
                    if (p.applicationInfo.uid > 10000) {
                        JSONObject jo = new JSONObject();
                        jo.put("label", p.applicationInfo.loadLabel(pm).toString());
                        jo.put("packageName", p.applicationInfo.packageName);
                        ja.put(jo);
                    }
                    System.out.print(ja);
                }        
        } catch (Exception e) {
            // TODO: handle exception
        }
        finally {
            // ... cleanup that will execute whether or not an error occurred ...
        }



}catch (Exception e) {
    // TODO: handle exception
}
finally {
    // ... cleanup that will execute whether or not an error occurred ...
}
    }}

Sorry cant get this to format the code properly.

like image 794
Hip Hip Array Avatar asked Mar 22 '11 15:03

Hip Hip Array


People also ask

Why does my Android not show installed apps?

For some Android models, the app will be installed automatically when it completes the downloading process. If you find the missing apps installed but still fail to show up on the home screen, you can uninstall the app and reinstall it. If necessary, you can also recover deleted apps on Android.

How can I get all my apps from Android to Android?

turn on your new phone and tap start. when you get the option, select “copy apps and data from your old phone” you can either do this with a cable to connect the phone or by selecting “A backup from an Android phone” follow the remaining instructions you're given to copy your data over.

How do I get an app Library on my Android?

You can see all the apps you've ever downloaded on your Android phone by opening the "My apps & games" section in your Google Play Store. The apps you've downloaded are divided into two sections: "Installed" (all the apps currently installed on your phone) and "Library" (all the apps that aren't currently installed).


2 Answers

This code logs name and package name of all the installed applications. You can easily check the log using LogCat (if you are using Eclipse).

Package name - name of the app's package.

Name - text label associated with the application. You can't use just appInfo.name as it will return null. Using appInfo.loadLabel(packageManager) you get the actual app's name like Speech Recorder instead of package name com.android.speechrecorder.

final PackageManager packageManager = getPackageManager();
List<ApplicationInfo> installedApplications = 
   packageManager.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo appInfo : installedApplications)
{
    Log.d("OUTPUT", "Package name : " + appInfo.packageName);
    Log.d("OUTPUT", "Name: " + appInfo.loadLabel(packageManager));
} 
like image 88
Nikolai Samteladze Avatar answered Sep 19 '22 15:09

Nikolai Samteladze


This is the code I use to list applications:

PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);

String activityName = rInfo.activityInfo.name;
List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);

for (ResolveInfo rInfo : list) {
    pkg = rInfo.activityInfo.applicationInfo.packageName;
    if (pm.getLaunchIntentForPackage(pkg) == null) {
      continue;
    }
    String label = rInfo.activityInfo.applicationInfo.loadLabel(pm).toString();
    arrayList.add(new AppEntry(label, activityName, pkg, null));
}

If you later on want to run application only knowing pkg and activityName you can do:

Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(pkg, activityname);
ctx.startActivity(intent);
like image 26
wojciechka Avatar answered Sep 19 '22 15:09

wojciechka