Skip to content

Instantly share code, notes, and snippets.

@Zlate87
Last active January 21, 2016 06:10
Show Gist options
  • Select an option

  • Save Zlate87/50f015e08840dc5f87aa to your computer and use it in GitHub Desktop.

Select an option

Save Zlate87/50f015e08840dc5f87aa to your computer and use it in GitHub Desktop.
A helper class with common methods useful when developing Android applications.
import android.content.Context;
import android.content.Intent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Andorid Helper class with common methids.
*/
public class AndroidHelper {
/**
* Method that will prepare the app debug log for it to be send to an email address.
*
* @param context the context
* @param email the email that should be pre populated in the email client
*/
public void sendAppLogByEmail(Context context, String email) {
try {
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder log = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
intent.putExtra(Intent.EXTRA_SUBJECT, "App Log");
intent.putExtra(Intent.EXTRA_TEXT, log.toString());
context.startActivity(intent);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment