Ich bin ein bisschen neu in Android Studio und so Zeug ... so blieb ich stecken. Ich brauche Bild zu erfassen und senden Klasse MainActivity erweitert Aktivität email.`public implementiert OnClickListener {Ich brauche Bild von der Kamera per E-Mail senden
EditText editTextEmail, editTextSubject, editTextMessage;
Button btnSend, btnAttachment;
String email, subject, message, attachmentFile;
Uri URI = null;
private static final int PICK_FROM_GALLERY = 101;
int columnIndex;
protected static final int CAMERA_PIC_REQUEST = 0;
Bitmap thumbnail;
File pic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextEmail = (EditText) findViewById(R.id.editTextTo);
editTextSubject = (EditText) findViewById(R.id.editTextSubject);
editTextMessage = (EditText) findViewById(R.id.editTextMessage);
btnAttachment = (Button) findViewById(R.id.buttonAttachment);
btnSend = (Button) findViewById(R.id.buttonSend);
btnSend.setOnClickListener(this);
btnAttachment.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == btnAttachment) {
openGallery();
}
if (v == btnSend) {
try {
email = editTextEmail.getText().toString();
subject = editTextSubject.getText().toString();
message = editTextMessage.getText().toString();
final Intent emailIntent = new Intent (Intent.ACTION_SEND);
// emailIntent.setType("message/rfc822");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { email });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
subject);
if (URI != null) {
emailIntent.putExtra(Intent.EXTRA_STREAM, URI.fromFile(pic));
}
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
this.startActivity(Intent.createChooser(emailIntent,
"Sending email..."));
} catch (Throwable t) {
Toast.makeText(this,
"Request failed try again: " + t.toString(),
Toast.LENGTH_LONG).show();
}
}
}
public void openGallery(){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(thumbnail);
try {
File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
if (root.canWrite()){
pic = new File(root, "pic.png");
FileOutputStream out = new FileOutputStream(pic);
thumbnail.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
}
} catch (IOException e) {
Log.e("BROKEN", "Could not write file " + e.getMessage());
}
}
}
}
, dass mein Code ist, kann ich ein Bild mit ihm nehmen oder E-Mail ohne Bild senden.
P.S. Ich finde meinen eigenen Fehler. Wo war keine Berechtigungen in Manifest-Datei
Erhalten Sie einen Fehler? –
Nein, keine Fehler. Ich muss irgendwie Methode ändern, um Foto zum Anhang hinzuzufügen. – Manta
[Bildschirmfoto] (https://gyazo.com/e0d55292f42f84c8617316398b27d946) Ich kann Bild hinzufügen, aber es sieht so aus. – Manta