To select multiple images use:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(Intent.createChooser(intent, "Selecione suas fotos"), SELECT_PICTURES);
As described in the documentation:
And to get the photos you must use the https://developer.android.com/reference/android/content/Intent#getClipData()
And to get the selected photos use:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent resultIntent)
{
super.onActivityResult(requestCode, resultCode, resultIntent);
if(requestCode == SELECT_PICTURES && resultCode == Activity.RESULT_OK && data.getClipData() != null) {
int j = data.getClipData().getItemCount();
for (int i = 0; i < j; i++)
Uri imageUri = data.getClipData().getItemAt(i).getUri();
//Faça o upload aqui
}
}
}
This will upload one by one. of course the HTTP and your server part is up to you, because it depends on what you did.
Vale remembers that there is the https://square.github.io/retrofit/ that can help you work with sending, if you have little experience with HTTP (most people spend years and don’t really master this, because it’s more complex than the word goes around)
So if you were to use Retrofit, you could get the images like this:
List<MultipartBody.Part> uploads = new ArrayList<>();
int j = data.getClipData().getItemCount();
for (int i = 0; i < j; i++)
File file = new File(data.getClipData().getItemAt(i).getUri());
RequestBody requestFile = RequestBody.create(MEDIA_TYPE_IMG, file);
uploads.add(MultipartBody.Part.createFormData("foto[]", file.getName(), requestFile));
}
Note that I applied foto[]
, but I didn’t really test the "Retrofit 2", if there is something wrong let me know.
Dear Robert phpmyadmin has nothing to do with all this: https://answall.com/a/115692/3635
– Guilherme Nascimento
Using what? Java with the pure Android API or using something else or lib the most? Give details, there is no unique way to do something.
– Guilherme Nascimento
Edited friend, I will post the code on which you managed to capture only one image.
– robertsouzalopesify