Android - Show an app chooser of all of the installed apps

Yuval

I want to open an app chooser that will list of the installed apps on the phone. When clicking on an app in the chooser I don't need to open it but get it's package name.

I know that I can create a specific intent for example with Intent.ACTION_SEND and the

Intent.createChooser()

I also know that I can list the installed packages using the package manager.

Is there a way to combine the 2 methods and create an app chooser with all of the installed apps?

Lazy

Chooser.java

public class Chooser extends ListActivity {
      AppAdapter adapter=null;

      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.chooser_layout);

        PackageManager pm=getPackageManager();
        Intent main=new Intent(Intent.ACTION_MAIN, null);

        main.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> launchables=pm.queryIntentActivities(main, 0);
        Collections.sort(launchables,
                         new ResolveInfo.DisplayNameComparator(pm));

        adapter=new AppAdapter(pm, launchables);
        setListAdapter(adapter);
      }

      @Override
      protected void onListItemClick(ListView l, View v,
                                     int position, long id) {

        ResolveInfo launchable=adapter.getItem(position);
        ActivityInfo activity=launchable.activityInfo;
        ComponentName name=new ComponentName(activity.applicationInfo.packageName,
                                             activity.name);

        /* SetResult 

        String pack_name = name.getPackageName();

        Intent intentMessage=new Intent();
        intentMessage.putExtra("MESSAGE_package_name", pack_name);
        setResult(1,intentMessage);
        finish();

        */




      }

      class AppAdapter extends ArrayAdapter<ResolveInfo> {
        private PackageManager pm=null;

        AppAdapter(PackageManager pm, List<ResolveInfo> apps) {
          super(Chooser.this, R.layout.row, apps);
          this.pm=pm;
        }

        @Override
        public View getView(int position, View convertView,
                              ViewGroup parent) {
          if (convertView==null) {
            convertView=newView(parent);
          }

          bindView(position, convertView);

          return(convertView);
        }

        private View newView(ViewGroup parent) {
          return(getLayoutInflater().inflate(R.layout.row, parent, false));
        }

        private void bindView(int position, View row) {
          TextView label=(TextView)row.findViewById(R.id.label);

          label.setText(getItem(position).loadLabel(pm));

          ImageView icon=(ImageView)row.findViewById(R.id.icon);

          icon.setImageDrawable(getItem(position).loadIcon(pm));
        }
      }


    }

chooser_layout.xml

    <?xml version="1.0" encoding="utf-8"?>
    <ListView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@android:id/list"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
    />

row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  >
  <ImageView android:id="@+id/icon"
      android:drawable="@drawable/ic_launcher"
    android:layout_width="45dp"
    android:layout_height="45dp"
    android:layout_alignParentLeft="true"
    android:paddingLeft="2px"
    android:paddingTop="3px"
    android:paddingBottom="3px"
    android:paddingRight="3px"
  />
  <TextView
    android:id="@+id/label"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/icon"
    android:textSize="18sp"
    android:text="Test App will here bla bla"
    android:paddingTop="2px"
    android:paddingBottom="2px"
  />

</RelativeLayout>

You can choose app like this:

Intent appIntent;
...

appIntent=new Intent(this,Chooser.class);
            startActivityForResult(appIntent, 1);



...


 @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data)
     {

       super.onActivityResult(requestCode, resultCode, data);

       if(null!=data){

         if(requestCode==1){
            //Do something
           String message=data.getStringExtra("MESSAGE_package_name");
           package_Name.SetText(message);
         }
     }

This will work for you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to list my app with a different name in other apps chooser intent in Android

From Dev

How to list my app with a different name in other apps chooser intent in Android

From Dev

Facebook and Youtube not show on Android Activity Chooser

From Dev

Need to know about app chooser in android

From Dev

My app won't show up on the chooser dialog for android.intent.action.VIEW with mime type video/* only on Marshmallow

From Dev

Android device does not show up in Android Device Chooser, but is listed in adb

From Dev

How to choose any app to launch with the app chooser in Android?

From Dev

Eclipse doesn't show Galaxy Nexus in Android Device Chooser

From Dev

Android Device Chooser not show my device in one device

From Dev

Not installed applications in Android settings/apps

From Dev

Not installed applications in Android settings/apps

From Dev

Duplicated apps installed by Android Studio

From Dev

Python show all installed packages

From Dev

How to delete app cache for all apps in Android M?

From Dev

App chooser Intent doesn't appear in android emulator

From Dev

Can't make my app appear in the chooser Android BROWSABLE

From Dev

Can't make my app appear in the chooser Android BROWSABLE

From Dev

Android Wear App not installed

From Dev

android app not installed error

From Dev

How to create a listview with 2 columns showing all installed android apps and the permissions along with it?

From Dev

How to send notifications through android app to all users installed and registered that android app?

From Dev

How to get all share apps installed on the device?

From Dev

is there any app for backup/ restore installed apps in ubuntu?

From Dev

How to start and App Chooser

From Dev

How to start and App Chooser

From Dev

Get number of installed apps on an Android device?

From Dev

how to sort installed apps date wise in android

From Dev

Ionic get installed apps on android device

From Dev

How to get installed applications in Android and no system apps?

Related Related

  1. 1

    How to list my app with a different name in other apps chooser intent in Android

  2. 2

    How to list my app with a different name in other apps chooser intent in Android

  3. 3

    Facebook and Youtube not show on Android Activity Chooser

  4. 4

    Need to know about app chooser in android

  5. 5

    My app won't show up on the chooser dialog for android.intent.action.VIEW with mime type video/* only on Marshmallow

  6. 6

    Android device does not show up in Android Device Chooser, but is listed in adb

  7. 7

    How to choose any app to launch with the app chooser in Android?

  8. 8

    Eclipse doesn't show Galaxy Nexus in Android Device Chooser

  9. 9

    Android Device Chooser not show my device in one device

  10. 10

    Not installed applications in Android settings/apps

  11. 11

    Not installed applications in Android settings/apps

  12. 12

    Duplicated apps installed by Android Studio

  13. 13

    Python show all installed packages

  14. 14

    How to delete app cache for all apps in Android M?

  15. 15

    App chooser Intent doesn't appear in android emulator

  16. 16

    Can't make my app appear in the chooser Android BROWSABLE

  17. 17

    Can't make my app appear in the chooser Android BROWSABLE

  18. 18

    Android Wear App not installed

  19. 19

    android app not installed error

  20. 20

    How to create a listview with 2 columns showing all installed android apps and the permissions along with it?

  21. 21

    How to send notifications through android app to all users installed and registered that android app?

  22. 22

    How to get all share apps installed on the device?

  23. 23

    is there any app for backup/ restore installed apps in ubuntu?

  24. 24

    How to start and App Chooser

  25. 25

    How to start and App Chooser

  26. 26

    Get number of installed apps on an Android device?

  27. 27

    how to sort installed apps date wise in android

  28. 28

    Ionic get installed apps on android device

  29. 29

    How to get installed applications in Android and no system apps?

HotTag

Archive