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