0

I have a list of all non-system application installed in the device .I am displaying these application name onto the listview . All is fine by now but I want to launch the application on selection of the items of the listview.How can I do so. here is what I have done till now.

  List<PackageInfo> PackList=new ArrayList();
  PackList = getPackageManager().getInstalledPackages(0);
    ArrayList<String> array=new ArrayList<String>();
    for (int i=0; i < PackList.size(); i++)
    {
        PackageInfo PackInfo = PackList.get(i);
        if ( (PackInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 1)
        {
            String AppName =   PackInfo.applicationInfo.loadLabel(getPackageManager()).toString();
            System.out.println(AppName);
            array.add(AppName);

        }
    }


    l=getListView();
    ArrayAdapter<String> adapter= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 ,array );
    l.setAdapter(adapter);
    l.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub

            String str=l.getItemAtPosition(arg2).toString();
            //intent intent=pm.getp

        }

    }); 
Shakeeb Ayaz
  • 6,200
  • 6
  • 45
  • 64

1 Answers1

1

Use Package name to start another app- here is simple code-

Intent appStartIntent = getPackageManager().getLaunchIntentForPackage("Your.package.Name");
startActivity(appStartIntent);
T_V
  • 17,440
  • 6
  • 36
  • 48
  • 1
    i modified the code .now my item will have package name instead of application name. thnx – Shakeeb Ayaz Aug 22 '13 at 10:46
  • 1
    You can also add app Icon in your listview if you needed. - http://stackoverflow.com/questions/17985500/how-to-get-app-icon-from-package-name/17985580#17985580 – T_V Aug 22 '13 at 10:58