1

I would like the user to be able to click on a button and have the option of selecting the gallery or similar apps or a camera activity I have in my app not the build-in one . I read the related answers here and here . However, I don't want to include the build-in camera app, but I want to include my Camera Activity.

I have the following set up so far, taken from the two links I posted:

Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
Intent gallIntent = new Intent(Intent.ACTION_GET_CONTENT);
gallIntent.setType("image/*");

Intent camIntent = new Intent(UserEventsActivity.this,CameraActivity.class);
camIntent.setComponent(new ComponentName("MCamera", "Camera"));

List<Intent> yourIntentsList = new ArrayList<Intent>();
yourIntentsList.add(camIntent);


List<ResolveInfo> listGall = getApplicationContext().getPackageManager().queryIntentActivities(gallIntent, 0);
for (ResolveInfo res : listGall) {
  final Intent finalIntent = new Intent(gallIntent);
  finalIntent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
  yourIntentsList.add(finalIntent);
}


pickIntent.putExtra(Intent.EXTRA_INTENT, yourIntentsList.toArray(new Parcelable[]{}));

pickIntent.putExtra(Intent.EXTRA_TITLE, "Select Source");
startActivityForResult(pickIntent, 1);

What results from this, is a large list of unrelated apps and services, most of which are actually repeated several times in the list. In addition, my camera activity is not among them. When I just do pickIntent.putExtra(Intent.EXTRA_INTENT,gallIntent) I do get the related gallery apps I want, but I can't add my activity.

Any ideas as to what I am doing wrong?

In addition, no service opens when I click on it. However, this may be related to the '1' arg in startActivityOnResult as I'm not exactly sure what to put for that arg.

Community
  • 1
  • 1
dylan7
  • 803
  • 1
  • 10
  • 22

1 Answers1

0

I came up with a possible solution, that seemed to work for me. I used a custom Dialog:

final Dialog choosePicContent = new Dialog(UserEventsActivity.this);
            ScrollView scrollContent = new ScrollView(UserEventsActivity.this);
            choosePicContent.addContentView(scrollContent, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            LinearLayout scrollLayout = new LinearLayout(UserEventsActivity.this);
            scrollContent.addView(scrollLayout);
            scrollLayout.setOrientation(LinearLayout.VERTICAL);

            TextView title = new TextView(UserEventsActivity.this);
            title.setText(R.string.selectsource);
            scrollLayout.addView(title);
            Intent gallIntent = new Intent(Intent.ACTION_GET_CONTENT);
            gallIntent.setType("image/*");

            final Intent camIntent = new Intent(UserEventsActivity.this,CameraActivity.class);

            ImageButton camButton = new ImageButton(UserEventsActivity.this);
            camButton.setImageDrawable(getApplicationContext().getDrawable(R.drawable.ic_menu_camera));
            camButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    camIntent.putExtra("User",current_user);
                    startActivity(camIntent);
                }
            });
            scrollLayout.addView(camButton);

          List<ResolveInfo> listGall = getApplicationContext().getPackageManager().queryIntentActivities(gallIntent, 0);
            for (ResolveInfo res : listGall) {


                    final Intent finalIntent = new Intent(gallIntent);
                    finalIntent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

                    ImageButton iconButton = new ImageButton(UserEventsActivity.this);
                    iconButton.setImageDrawable(res.activityInfo.loadIcon(getPackageManager()));
                    iconButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            startActivityForResult(finalIntent,1);
                        }
                    });
                    scrollLayout.addView(iconButton);

            }
            choosePicContent.show();
dylan7
  • 803
  • 1
  • 10
  • 22