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

2

I would like to know how to remove the option "Photos" from the options selector and leave only the "Camera" and "Gallery" options. Because it does not work, it is unnecessary since the "Gallery" does the same and better. Here is my code and the result:

Activity EditContactivity Activity:

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);
    }   

}   

Upload 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;

}

}

Result:

    
asked by anonymous 31.01.2016 / 02:11

3 answers

0

Well, with the help of @Pablo's response and comments I came to the conclusion that the best practice is to make it work, however, there must be some way to check if one of the options the app is going to display is working before displaying and so if it is not it does not display this option, such as what happens with WattsApp that does not display this option on my phone and displays in others and in the app the code of that question it displays, but the error. That way I will try to make it work and try to make it check the functional options before displaying. Thanks for everyone's attention.

    
02.02.2016 / 05:40
1

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

    
31.01.2016 / 02:45
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);

Do not forget that REQUEST_CODE_LOAD_IMAGE is a constant defined by you that will be used in the onActivityResult method.

    
01.02.2016 / 11:34