Absturz beim Absenden einer Email mit Bildanhang

I

ioantudor

Neues Mitglied
0
Hi,

ich versuche ein kleines Programm zu schreiben, welches den Benutzer ein Bild schiessen laesst mit der Cam und dieses direkt als Email verschickt. Nach der Auswahl der Email Applikation stuerzt es jedoch ab. Vielleicht hat jemand eine Idee woran es liegen koennte. Ich vermute, dass vielleicht die Email Applikation nicht mit dem Format meiner Email klar kommt.

[Java] public class Email_Send extends Activity { Button send; EditText address, | Pastebin.de

Danke
 
ich würde mal behaupten, daß beim 2. und 3. putExtra das .toString()
von getText() fehlt. beim debuggen müßtest du das allerdings merken :cool2:

Code:
[COLOR=#000000][COLOR=#0000BB]
emailIntent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]putExtra[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]android[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]content[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]Intent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]EXTRA_EMAIL[/COLOR][COLOR=#007700], 
                        new [/COLOR][COLOR=#0000BB]String[/COLOR][COLOR=#007700][] { [/COLOR][COLOR=#0000BB]address[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getText[/COLOR][COLOR=#007700]().[/COLOR][COLOR=#0000BB]toString[/COLOR][COLOR=#007700]() }); 

[/COLOR][COLOR=#0000BB]emailIntent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]putExtra[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]android[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]content[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]Intent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]EXTRA_SUBJECT[/COLOR][COLOR=#007700], 
                        [/COLOR][COLOR=#0000BB]subject[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getText[/COLOR][COLOR=#007700]()); 

[/COLOR][COLOR=#0000BB]emailIntent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]putExtra[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]android[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]content[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]Intent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]EXTRA_TEXT[/COLOR][COLOR=#007700], 
                        [/COLOR][COLOR=#0000BB]emailtext[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getText[/COLOR][COLOR=#007700]());[/COLOR][/COLOR]

außerdem benutzt du 2 mal emailIntent.setType, ich denke 1 mal richtig gesetzt reicht das.

ansonsten sieht der code ja recht einfach aus, wollte mich demnächst nämlich auch mal mit der kamera beschäftigen und bilder verschicken, danke für die vorlage :smile:
 
Danke, aber das löst es leider nicht.
 
es funktioniert jetzt mit folgendem code:

Code:
public class Email_Send extends Activity {
	Button send;
	EditText address, subject, emailtext;

	private static final int IMAGE_CAPTURE = 0;
	private static final String TAG = "#### email_Send ####";
	Bitmap bitmap = null;
	File pic;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		send = (Button) findViewById(R.id.emailsendbutton);
		address = (EditText) findViewById(R.id.emailaddress);
		subject = (EditText) findViewById(R.id.emailsubject);
		emailtext = (EditText) findViewById(R.id.emailtext);

		Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
		startActivityForResult(intent, IMAGE_CAPTURE);

		send.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

				emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { address.getText().toString() });
				emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText().toString());
				emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText().toString());
				emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));
				emailIntent.setType("image/jpeg");

				Email_Send.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
			}
		});
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (requestCode == IMAGE_CAPTURE) {
			if (resultCode == RESULT_OK) {

				bitmap = (Bitmap) data.getExtras().get("data");

				try {
					File imageFile = Environment.getExternalStorageDirectory();

					if (imageFile.canWrite()) {
						pic = new File(imageFile, "pic.jpg");
						FileOutputStream out = new FileOutputStream(pic);
						bitmap.compress(CompressFormat.JPEG, 90, out);
						out.flush();
						out.close();
						Log.v(TAG, "saved bitmap!");
					} else {
						Log.e(TAG, "Could not write file, root.canWrite failed! ");
					}
				} catch (IOException e) {
					Log.e(TAG, "Could not write file " + e.getMessage());
				}

			} else if (resultCode == RESULT_CANCELED) {
				Log.e(TAG, "Wrong result from Cam activity! ");
			} else {
			}
		}
	}
}
 

Ähnliche Themen

D
  • Data2006
Antworten
14
Aufrufe
486
jogimuc
J
S
  • Sempervivum
Antworten
2
Aufrufe
607
Sempervivum
S
B
Antworten
3
Aufrufe
1.307
swa00
swa00
Zurück
Oben Unten