Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1.  public static void sendEmail(Activity activity, String appName, @Nullable Throwable sendEx) {
  2.         String version;
  3.         try {
  4.             version = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
  5.         } catch (PackageManager.NameNotFoundException ex) {
  6.             version = activity.getString(R.string.unknown);
  7.         }
  8.  
  9.         Intent intent = new Intent(Intent.ACTION_SEND)
  10.                 .setType("message/rfc822")
  11.                 .putExtra(Intent.EXTRA_EMAIL, new String[]{activity.getString(R.string.email)})
  12.                 .putExtra(Intent.EXTRA_SUBJECT, appName);
  13.  
  14.         String emailBody = "OS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")" +
  15.                         "\nOS API Level: " + android.os.Build.VERSION.SDK_INT +
  16.                         "\nDevice: " + android.os.Build.DEVICE +
  17.                         "\nModel (and Product): " + android.os.Build.MODEL + " (" + android.os.Build.PRODUCT + ")" +
  18.                         "\nApplication version: " + version +
  19.                         "\n\nProvide bug/feature details";
  20.  
  21.         if (sendEx != null) {
  22.             emailBody += "\n\n\n";
  23.             emailBody += Logging.getStackTrace(sendEx);
  24.         }
  25.  
  26.         intent.putExtra(Intent.EXTRA_TEXT, emailBody);
  27.  
  28.         Logging.LogFile log = Logging.getLatestLogFile(activity, true);
  29.         if (log != null) {
  30.             try {
  31.                 intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(Logging.moveLogFileToExternalStorage(activity, log)));
  32.             } catch (ParseException | IOException ignored) {
  33.             }
  34.         }
  35.  
  36.         try {
  37.             activity.startActivity(Intent.createChooser(intent, "Send mail..."));
  38.         } catch (android.content.ActivityNotFoundException ex) {
  39.             CommonUtils.UIToast(activity, ToastMessage.NO_EMAIL_CLIENT);
  40.         }
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement