Feb 6, 2013

List all installed activities

We can list all activities that can be performed for the given intent by calling PackageManager.queryIntentActivities(Intent intent, int flags).

List all installed activities


package com.example.androidlistapps;

import java.util.List;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import android.app.ListActivity;
import android.content.Intent;
import android.content.pm.ResolveInfo;

public class MainActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        
        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> intentList = getPackageManager().queryIntentActivities(intent, 0);
        
        setListAdapter(new ArrayAdapter<ResolveInfo>(
          this, 
          android.R.layout.simple_list_item_1, 
          intentList));
        
        Toast.makeText(getApplicationContext(), 
          "no of activities: " + intentList.size(), 
          Toast.LENGTH_LONG).show();
    }

}


Next: Get application details via ResolveInfo


No comments:

Post a Comment

Infolinks In Text Ads