Syed
Syed

Reputation: 550

How to display list of application names from package names

I am developing an application which show all current applications. I am getting the apps package names, thats good but not specific applications name How should I do it, I am using following code:

Context context = this.getApplicationContext();
ActivityManager mgr = (ActivityManager)context.getSystemService(ACTIVITY_SERVICE);

List<RunningTaskInfo> tasks = mgr.getRunningTasks(30);

List<ActivityManager.RunningAppProcessInfo> tasksP = mgr.getRunningAppProcesses();

int numOfTasks = tasks.size();

for(int i = 0; i < numOfTasks; i++){
    ActivityManager.RunningAppProcessInfo task = tasksP.get(i);

    PackageInfo myPInfo = null;
    try {
        myPInfo = getPackageManager().getPackageInfo(task.processName, 0);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }   
    Toast.makeText(location.this,
            task.processName,
            Toast.LENGTH_LONG).show();
}

Also please tell me how to display these apps name in check boxes, so that I can kill my desired app.

Upvotes: 1

Views: 1798

Answers (2)

Terril Thomas
Terril Thomas

Reputation: 1506

    Intent filter = new Intent(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_LAUNCHER);
    Context context = getApplicationContext();

    PackageManager manager = getPackageManager();


  List<ResolveInfo> infos = getPackageManager().queryIntentActivities(filter,0);

    List<Intent> filters = new ArrayList<Intent>();
    filters.add(filter);

    ComponentName component = new ComponentName(context.getPackageName(), MainActivity.class.getName());
    List<ComponentName> activities = new ArrayList<ComponentName>();


    //ComponentName[] components = new ComponentName[] {new ComponentName("//com.neo.application", "com.neo.application.Application"), component};


      try {
        manager.getApplicationInfo(//PACKAGE_NAME);//just Ctrl+space it u'll get the package names.
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Upvotes: 2

Venky
Venky

Reputation: 11107

Try this code for getting Installed Application in your phone :

 final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    final List<ResolveInfo> pkgAppsList = this.getPackageManager().queryIntentActivities( mainIntent, 0);

    List<String> componentList = new ArrayList<String>();

    for (ResolveInfo ri : pkgAppsList) {
        if (ri.activityInfo != null) {
            String app_name=ri.activityInfo.loadLabel(getPackageManager()).toString();
            Log.d("Apps Name", ""+ri.activityInfo.loadLabel(getPackageManager()).toString());
        }
    }
}

Check this Link for further Reference :

Installed Application Details

Upvotes: 4

Related Questions