开发者

Sending email using ACTION_SENDTO keeps failing

I am trying to send an email with logs using send-me-logs to myself. I don't want to use an email client, but just send the email "silently". I have also set android.permission.INTERNET in my app. I am using this code:

Uri emailUri = Uri.parse("mailto:" + email);
StringBuilder sb = new StringBuilder(preface).append(LINE_SEPARATOR);
String phoneInfo = collectPhoneInfo();
sb.append(LINE_SEPARATOR).append(phoneInfo);
for (String line : lines)
    sb.append(LINE_SEPARATOR).append(l开发者_JS百科ine);
String content = sb.toString();
Intent intent = new Intent(Intent.ACTION_SENDTO, emailUri);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, content);
mContext.startActivity(intent);

startActivity doesn't throw an exception, but my LogCat says:

08-21 16:30:22.418: ERROR/JavaBinder(9269): !!! FAILED BINDER TRANSACTION !!!

I am on a real device (Samsung Galaxy S2). Any ideas?


Try putting the subject and text inside the emailUri as params:

Uri emailUri = Uri.parse("mailto:" + email + "?subject" = subject + "&body=" + content);

And remove the 2 intent.putExtra lines

Then open the chooser:

intent.setData(uri);
startActivity(Intent.createChooser(intent, "Email logs"));


The problem is with

intent.putExtra(Intent.EXTRA_TEXT, content);

content is too large to successfully bind into the bundle. (bundle has a size limit i've heard people say 500kb or 1024kb but not really sure)

If you really want to send all your log information which could be a lot of information. I would write out to file, and attach the file to the email as an .txt attachment

Sample code that could help achieve this...

public static final String filename = "log.txt";

// Opening a file for output
logFile = new File(Environment.getExternalStorageDirectory(), filename);
FileWriter fileWriter = new FileWriter(logFile, true);

//open for appending   
bufferedWriter = new BufferedWriter(fileWriter);

for (String line : logInfoToWrite) {
    bufferedWriter.write(line);
}

AND...

// adding a file as an attachment    
File logFile = new File(Environment.getExternalStorageDirectory(), filename);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(logFile));

notice: sample code is not complete and has some exception handling left out, and writer flushes, but should give enough of a gist as too how to accomplish writing log entries to a file, and then attaching that file to an email intent as a txt file.

Hope this helps others out there. I noticed this is a fairly old post

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜