Intégrer une photo prise de l'APN dans une Imageview
Bonjour,
je réalise une activity qui récupère du texte (destinataire, objet + corps de mail) pour ensuite reformater un email qui peut expédier par un client de messagerie (type gmail).
Pour la partie texte, l'activity fonctionne sans problème. La ou ca se gâte, c'est pour y intégrer une photo dans ce fameux mail. J’accède à l’ouverture de la fonction APN, prise de photo OK, mais à la validation de cette photo, l'appli plante (au lieu de revenir sur l'activity, m'afficher une vignette de la photo, pour l'envoi mail.
Donc qui pourrait m'aider sur la partie incrustation de la photo dans mon imagview ?
Les permissions sont OK dans le manifest,
Merci
Activity xml :
Code:
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000"
tools:context=".MainActivity9">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView4" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textViewPhoneNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A :"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="#000000"
android:layout_marginLeft="5dp"
android:textColor="#ffffff" />
<EditText
android:id="@+id/editTextTo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:background="#ffffff"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="blablabla@gmail.com">
<requestFocus />
</EditText>
<TextView
android:id="@+id/textViewSubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Objet :"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="#000000"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:textColor="#ffffff" />
<EditText
android:id="@+id/editTextSubject"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
</EditText>
<TextView
android:id="@+id/textViewMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message : "
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="#000000"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:textColor="#ffffff" />
<EditText
android:id="@+id/editTextMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="5"
android:background="#ffffff"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="photo"
android:id="@+id/button45"
android:layout_marginTop="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ImageView3" />
<Button
android:id="@+id/buttonSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Envoyer" />
</LinearLayout>
</ScrollView>
</LinearLayout> |
et pour l'activity java :
Code:
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| package essai.app;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity9 extends Activity {
Button buttonSend;
Button BT;
EditText textTo;
EditText textSubject;
EditText textMessage;
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main9);
buttonSend = (Button) findViewById(R.id.buttonSend);
BT = ((Button) findViewById(R.id.button45));
textTo = (EditText) findViewById(R.id.editTextTo);
textSubject = (EditText) findViewById(R.id.editTextSubject);
textMessage = (EditText) findViewById(R.id.editTextMessage);
img = (ImageView) findViewById(R.id.imageView3);
BT.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity9.this, "Activation de l'appareil photo", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
textTo.setText("blablabla@gmail.com");
String to = textTo.getText().toString();
String subject = textSubject.getText().toString();
String message = textMessage.getText().toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
//need this to prompts email client only
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choix du service MAIL :"));
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Bitmap bit= (Bitmap) data.getExtras().get("data");
img.setImageBitmap(bit);
}
} |