Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void sendEmail(Activity activity, String appName, @Nullable Throwable sendEx) {
- String version;
- try {
- version = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
- } catch (PackageManager.NameNotFoundException ex) {
- version = activity.getString(R.string.unknown);
- }
- Intent intent = new Intent(Intent.ACTION_SEND)
- .setType("message/rfc822")
- .putExtra(Intent.EXTRA_EMAIL, new String[]{activity.getString(R.string.email)})
- .putExtra(Intent.EXTRA_SUBJECT, appName);
- String emailBody = "OS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")" +
- "\nOS API Level: " + android.os.Build.VERSION.SDK_INT +
- "\nDevice: " + android.os.Build.DEVICE +
- "\nModel (and Product): " + android.os.Build.MODEL + " (" + android.os.Build.PRODUCT + ")" +
- "\nApplication version: " + version +
- "\n\nProvide bug/feature details";
- if (sendEx != null) {
- emailBody += "\n\n\n";
- emailBody += Logging.getStackTrace(sendEx);
- }
- intent.putExtra(Intent.EXTRA_TEXT, emailBody);
- Logging.LogFile log = Logging.getLatestLogFile(activity, true);
- if (log != null) {
- try {
- intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(Logging.moveLogFileToExternalStorage(activity, log)));
- } catch (ParseException | IOException ignored) {
- }
- }
- try {
- activity.startActivity(Intent.createChooser(intent, "Send mail..."));
- } catch (android.content.ActivityNotFoundException ex) {
- CommonUtils.UIToast(activity, ToastMessage.NO_EMAIL_CLIENT);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement