Method 3

Go to the MainActivity file and refer to the following code. Below is the code for the MainActivity file. Comments are added inside the code to understand the code in more detail.

Java




import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
  
public class MainActivity extends AppCompatActivity {
    ListView listView;
    TextView text;
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
  
        // initialise layout
        listView = findViewById(R.id.listview);
        text = findViewById(R.id.totalapp);
    }
  
    public void getallapps(View view) throws PackageManager.NameNotFoundException {
        final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  
        // get list of all the apps installed
        List<ResolveInfo> ril = getPackageManager().queryIntentActivities(mainIntent, 0);
        List<String> componentList = new ArrayList<String>();
        String name = null;
        int i = 0;
  
        // get size of ril and create a list
        String[] apps = new String[ril.size()];
        for (ResolveInfo ri : ril) {
            if (ri.activityInfo != null) {
                // get package
                Resources res = getPackageManager().getResourcesForApplication(ri.activityInfo.applicationInfo);
                // if activity label res is found
                if (ri.activityInfo.labelRes != 0) {
                    name = res.getString(ri.activityInfo.labelRes);
                } else {
                    name = ri.activityInfo.applicationInfo.loadLabel(
                            getPackageManager()).toString();
                }
                apps[i] = name;
                i++;
            }
        }
        // set all the apps name in list view
        listView.setAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, apps));
        // write total count of apps available.
        text.setText(ril.size() + " Apps are installed");
    }
  
    @Override
    protected void onStart() {
        super.onStart();
    }
}


Kotlin




import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.ListView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
  
class MainActivity : AppCompatActivity() {
    lateinit var listView: ListView
    lateinit var text: TextView
      
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
  
        // initialise layout
        listView = findViewById(R.id.listview)
        text = findViewById(R.id.totalapp)
    }
  
    @Throws(PackageManager.NameNotFoundException::class)
    fun getAllApps() {
        val mainIntent = Intent(Intent.ACTION_MAIN, null)
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER)
  
        // get list of all the apps installed
        val ril = packageManager.queryIntentActivities(mainIntent, 0)
        val componentList: List<String> = ArrayList()
        lateinit var name: String
        var i = 0
  
        // get size of ril and create a list
        val apps = arrayOfNulls<String>(ril.size)
        for (ri in ril) {
            if (ri.activityInfo != null) {
                // get package
                val res = packageManager.getResourcesForApplication(ri.activityInfo.applicationInfo)
                // if activity label res is found
                name = if (ri.activityInfo.labelRes != 0) {
                    res.getString(ri.activityInfo.labelRes)
                } else {
                    ri.activityInfo.applicationInfo.loadLabel(packageManager).toString()
                }
                apps[i] = name
                i++
            }
        }
        // set all the apps name in list view
        listView.adapter = ArrayAdapter(this@MainActivity, android.R.layout.simple_list_item_1, apps)
        // write total count of apps available.
        text.text = ril.size.toString() + " Apps are installed"
    }
  
    override fun onStart() {
        super.onStart()
    }
}


Output:



Different Ways to Get List of All Apps Installed in Your Android Phone

In this article, we are going to show the list of all the installed apps on your Android phone. So here we are going to learn how to implement that feature in three different ways. Note that we are going to implement this project in both Java and Kotlin Programming languages for Android.

Similar Reads

Step-by-Step Implementation

Step 1: Create a New Project in Android Studio...

Method 1

...

Method 2

Go to the MainActivity file and refer to the following code. Below is the code for the MainActivity file. Comments are added inside the code to understand the code in more detail....

Method 3

...

Contact Us