Ich erstelle eine Android-Anwendung, wo ich ein Bild von der Kamera gesendet werden muss, aber aus Sicherheitsgründen kann ich nicht dieses Bild auf dem Benutzergerät gespeichert haben.Bitmap per E-Mail senden, ohne es auf dem Gerät zu speichern - Android
Jede Lösung, die ich beim Senden einer Bitmap per E-Mail gefunden habe, scheint sie im Verzeichnis der App zu archivieren und dann ihren Pfad zu verwenden, um sie zu senden.
In meiner Anwendung wird das Bild nur für diese Aktivität (und wenn per E-Mail gesendet) verwendet.
Soo ... Gibt es überhaupt ein Bitmap ohne es zu speichern?
EDIT: Hier ist, wie ich versuche, dies ab sofort zu tun (es funktioniert nicht BTW).
für die Kamera aufrufen:
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Opens camera app
foto = true;
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);
}
});
das Ergebnis Erste
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//Converts picture to PNG
if ((requestCode == CAMERA_PIC_REQUEST) && (resultCode == RESULT_OK)) {
thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image = (ImageView) findViewById(R.id.image_comment);
image.setImageBitmap(thumbnail);
try {
File root = Environment.getExternalStorageDirectory();
if (root.canWrite()){
// We + "/MapTest" to make it storage on a deeper directory for our application
problemPicture = new File(getCacheDir(), "problemPicture.png");
FileOutputStream out = new FileOutputStream(problemPicture);
thumbnail.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
}
} catch (IOException e) {
Log.e("BROKEN", "Could not write file " + e.getMessage());
}
}
}
Senden E-Mail (foto true rechts, bevor sie eingestellt ist):
public void sendEmail(){
Intent i = new Intent(Intent.ACTION_SEND);
if(foto) { //if user attached a pic
i.setType("image/png");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "Assistencia Tecnica");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(problemPicture));
i.putExtra(Intent.EXTRA_TEXT, commentText.getText());
problemPicture.delete();
try {
startActivity(Intent.createChooser(i, "Enviando Email..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(StatusActivity.this, "Comunicaçaõ Falhou",
Toast.LENGTH_SHORT).show();
}
try {
// We try to delete the picture
boolean success = problemPicture.delete();
if(success) {
Log.i(TAG, "File deleted successfully");
} else {
if(problemPicture.isDirectory()) {
success = deleteDirectory(problemPicture);
if(success) {
Log.i(TAG, "Directory deleted successfully!");
} else {
Log.i(TAG, "Could not delete directory");
}
}
Log.i(TAG, "File could not be deleted");
}
} catch (NullPointerException e) {
// In case we don't find it
Log.i(TAG, "File not found");
}
try {
deleteFile("problemPicture.png");
} catch(NullPointerException e) {
Log.i(TAG, "Context file not found");
}
}
else {
i.setType("plane/text");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "Assistencia Tecnica");
i.putExtra(Intent.EXTRA_TEXT, commentText.getText());
try {
startActivity(Intent.createChooser(i, "Enviando Email..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(StatusActivity.this, "Comunicaçaõ Falhou", Toast.LENGTH_SHORT).show();
}
}
}
Aktivität beenden
private void endActivity() {
//Back to Maps Activity
boolean success = false;
try {
success = problemPicture.delete();
} catch(NullPointerException e) {
Log.d(TAG, "No picture found");
}
if(success) {
Log.i(TAG, "Picture deleted");
} else {
Log.i(TAG, "Picture could not be deleted");
}
success = deleteFile("problemPicture.png");
if(success) {
Log.d(TAG, "File deleted");
} else {
Log.d(TAG, "File could not be deleted");
}
Toast.makeText(getApplicationContext(), "OS Finalizada",Toast.LENGTH_SHORT).show();
Intent it = new Intent(StatusActivity.this, MapsActivity.class)
.putExtra("index", index);
startActivity(it);
}
Sorry für die Wand von schlechtem Code und danke!
zeigen Sie Ihren Code, wir können Ihnen helfen! –
Um dies zu tun, denke ich, dass Sie die E-Mail-Versand direkt in Ihre App erstellen müssen. Selbst wenn Sie einen Anhang "im Speicher" übergeben (oder die Datei auf dem "Datenträger" nach dem Senden löschen könnten), wird mit dem E-Mail-Intent das E-Mail-Programm auf dem Telefon des Benutzers gestartet, von dem die meisten Kopien gesendeter E-Mails erhalten . – TripeHound
@SohailZahid Done –