Last active
January 21, 2016 06:10
-
-
Save Zlate87/50f015e08840dc5f87aa to your computer and use it in GitHub Desktop.
A helper class with common methods useful when developing Android applications.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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