Skip to content

Commit

Permalink
Merge pull request #2 from nohum/dev-add-body-text
Browse files Browse the repository at this point in the history
Dev add body text
  • Loading branch information
notz committed Feb 23, 2015
2 parents 56f6873 + 00998ae commit 30e253c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected void onCreate(Bundle savedInstanceState) {
shareLogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LoggingHelper.shareLog(MainActivity.this, null, "This is a logging demo");
LoggingHelper.shareLog(MainActivity.this, null, "This is a logging demo", "This is the optional body text");
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -60,20 +58,23 @@ public static void setupUncaughtExceptionHandler() {
}

public static void shareLog(final Context context) {
shareLog(context, null, null);
shareLog(context, null, null, null);
}

public static void shareLog(final Context context, final String email, final String subject) {
shareLog(context, email, subject, null);
}

public static void shareLog(final Context context, final String email, final String subject, final String body) {
AndroidHandler androidHandler = getAndroidHandler();
if (androidHandler != null) {
androidHandler.flush();

shareLog(context, androidHandler.getTag(), email, subject);
doShareLog(context, androidHandler.getTag(), email, subject, body);
}
}

private static void shareLog(final Context context, final String tag, final String email, final String subject) {
private static void doShareLog(final Context context, final String tag, final String email, final String subject, final String body) {

new AsyncTask<Void, Void, Uri>() {
@Override
Expand Down Expand Up @@ -126,6 +127,11 @@ protected void onPostExecute(Uri result) {
if (subject != null) {
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
}
if (body != null) {
// According to http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND a send-intent should
// either have EXTRA_TEXT or EXTRA_STREAM set, both setting both seems to be respected by most receivers (e.g. GMail)
intent.putExtra(android.content.Intent.EXTRA_TEXT, body);
}
intent.putExtra(android.content.Intent.EXTRA_STREAM, result);

try {
Expand Down

0 comments on commit 30e253c

Please sign in to comment.