Skip to main content

Get List of All Installed Apps

For getting the list of all apps installed in the device and to show it on a listview we can use the following code:

MainActivity.java

import java.util.ArrayList;
import java.util.List;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends ActionBarActivity {
 ArrayList results_sys_app = new ArrayList();
 ArrayAdapter<applicationinfo>adapter;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
  mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  final List<applicationinfo> pkgAppsList = this.getPackageManager().getInstalledApplications(    PackageManager.GET_UNINSTALLED_PACKAGES);
  PackageManager pm2 = (PackageManager) this.getPackageManager();
  ListView L1 = (ListView) findViewById(R.id.listView1);

  for (int i = 0; i < pkgAppsList.size(); i++) {
   /*
    * for getting the app name
    */
   results_sys_app.add(pkgAppsList.get(i).loadLabel(pm2).toString());

   /*
    * for getting the icon of the app we can use the following
    * commented code
    */

   
   // results_sys_app.add(pkgAppsList.get(i).loadIcon(pm2).toString());
   adapter = new ArrayAdapter<applicationinfo>(this,
     android.R.layout.simple_list_item_1, android.R.id.text1,
     results_sys_app);
   L1.setAdapter(adapter);

  }

 }

}

activity_main.xml


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.allapps.MainActivity"
    tools:ignore="MergeRootFrame" >
    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>
</FrameLayout>

Comments

Popular posts from this blog

Server communication in Android

In Android we can communicate with server using HTTP request methods for getting some details from the server.We use RESTful service.Mainly we use two types of HTTP request HTTP GET(),HTTP POST() methods. In some case we have to give some values to the server for fetching some informations, then we use commonly HTTP POST() and if we simply want to request for some datas we use HTTP GET(). Lets see HTTP POST() method. public void getResponse(String a, String b) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("URL"); //here write the url List < NameValuePair > nameValueList = new ArrayList < NameValuePair > (2); nameValueList.add(new BasicNameValuePair("keyword", a)); nameValueList.add(new BasicNameValuePair("keyword", b)); try { httppost.setEntity(new UrlEncodedFormEntity(nameValueList)); HttpResponse response = httpclient.execute(httppost); Log.i(...

How to create a flash light on Android

I always wonder the use of a flash light on a phone. This simple app is more useful than anything. So here is the code to build a flashlight app, MainActivity.java import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.pm.PackageManager; import android.hardware.Camera; import android.hardware.Camera.Parameters; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageButton; public class MainActivity extends Activity { ImageButton btnSwitch; private Camera camera; private boolean isFlashOn; private boolean hasFlash; Parameters params; MediaPlayer mp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // flash switch button ...

How to record and save a video in Android

Let's record a video :). Check the code snippet. First need to give necessary permissions. So add these permissions to AndroidManifest.xml   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />   <uses-permission android:name="android.permission.RECORD_AUDIO" /> MainActivity.java import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener { Button btn_record; pu...