Android how to remove "Photos" option from the options selector and leave only "Camera" and "Gallery" options

Asked

Viewed 96 times

2

I would like to know how to remove the option "Photos" from the options selector and leave only the options "Camera" and "Gallery". As well as not working, it is unnecessary since the "Gallery" does the same thing and better. Below follows my code and the result:

Activity Editarcontaactivity:

public class EditarContaActivity extends Activity implements OnClickListener {

private static int RESULT_LOAD_IMAGE = 1;    
Button btneditar;   
File file;

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

    imguser = (ImageView)findViewById(R.id.imgdefault_user);

    btneditar = (Button)findViewById(R.id.btneditar1);
    btneditar.setOnClickListener(this);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_editarconta, menu);
    return true;
}

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


    //Detects request codes
    if(requestCode == RESULT_LOAD_IMAGE && resultCode == Activity.RESULT_OK) {
        Bitmap bitmap = null;
        Bundle extras = data.getExtras();
        bitmap = extras.getParcelable("data");

        FileOutputStream fos;
        try {
            fos = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);  
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

        imguser.setImageBitmap(bitmap);

    }
}

public void onClick(View v) {
    // TODO Auto-generated method stub      

        String filename = "profile.jpg";
        file = new File(Environment.getExternalStorageDirectory(), filename);

        Intent testeIntent = CarregarImagem.pegaIntencao(this, file);

        startActivityForResult(testeIntent, RESULT_LOAD_IMAGE);
    }   

}   

Cargo class:

public class CarregarImagem {   

public static Intent pegaIntencao(Context contexto, File file) {

    // Intenção da Câmera
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = contexto.getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam){
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
        cameraIntents.add(intent);
    }

    // Intenção da Galeria
    final Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    // Seletor de opções
    final Intent chooserIntent = Intent.createChooser(galleryIntent, "Foto de Perfil");

    // Add opção de camera 
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));

    return chooserIntent;

}

}

Upshot: inserir a descrição da imagem aqui

3 answers

1

You can’t do this. Who defines what appears there is Android, based on the type of Intent that you passed and in which applications are listening to this type of action. Who should decide whether this option is relevant or not is the (a) user(a), either by clicking "Always" (when available) or by uninstalling/disabling the application.

  • But the watts app does not allow appear this option, I think it is pq it does not work, so when I click on it appears the photos, but while selecting any photo the app causes an error.

  • 1

    I just checked here that Whatsapp displays a lot of apps to choose from, including Photos: ( https://i.imgur.com/pdAHuLh.jpg ) If Photos doesn’t work for the action you want, this is the problem you have to solve. Even if you can, it is not good to limit the preferences of the (a) user(a). I also had this problem once and made it work. You too can.

  • Did you check it out where? Because I was talking about the part where you’re gonna change your profile picture and not the part about texting.

  • This part is in settings/Profile.

  • I went to settings/profile.

  • Seriously because in my does not appear this option, appears only gallery, camera and the option to remove photo, already when I run the app of this project appears.

  • I just checked on another phone here and this option appears, I think this option Photos from my phone is not working or the Watts App checks if the option will work first before displaying. I really don’t know how I would do this kind of check if that’s the case.

  • @Gustavoalmeidacavalcante Open another question specifically for this.

Show 3 more comments

0


Well, with the help of the reply and @Pablo comments I have come to the conclusion that the best practice is to make it work, but there must be some way to check if one of the options that the app will display is working before displaying and so if it is not it does not display this option, like what happens with Wattsapp that does not display this option on my phone and displays in the others and in the app code of this question it displays, but error. This way I will try to make it work and try to make it check the functional options before displaying. Thank you for everyone’s attention.

0

This way the camera does not appear:

 Intent galleryIntent = new Intent(
                Intent.ACTION_PICK,
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
 galleryIntent.setType("image/*");
 final Intent chooserIntent =
                Intent.createChooser(galleryIntent, "Um texto qualquer");
 startActivityForResult(chooserIntent, REQUEST_CODE_LOAD_IMAGE);

Don’t forget that REQUEST_CODE_LOAD_IMAGE is a constant defined by you that will be used in the onActivityResult method.

  • But it is not the camera I wanted to take was the option "Photos". But Valew by the attention.

  • I’m sorry I misunderstood. I’ll leave the answer anyway, you can help someone. For the camera you can try Intent cameraIntent = new Intent(Mediastore.ACTION_IMAGE_CAPTURE);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.