1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
public void onClick(View v) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case SELECT_PHOTO:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
InputStream imageStream = null;
try {
//picturesone.setText(selectedImage.getPath());
//File file = new File();
FileDataSource datasource1 = new FileDataSource(selectedImage.getPath());
DataHandler handler1 = new DataHandler(datasource1);
MimeBodyPart autruche = new MimeBodyPart();
autruche.setDataHandler(handler1);
autruche.setFileName(datasource1.getName());
picturesone.setText(datasource1.getName());
} catch (MessagingException e) {
e.printStackTrace();
}
//Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
}
}
MimeMultipart mimeMultipart = new MimeMultipart();
try {
mimeMultipart.addBodyPart(content);
mimeMultipart.addBodyPart(autruche);
} catch (MessagingException e) {
e.printStackTrace();
} |
Partager