Mega Code Archive

 
Categories / Android / Network
 

Launch the email intent

import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build; class Main {   /**    * Launch the email intent    * @param context    * @param subject    * @param sendTo    * @param includeDebug    */   public static void launchEmailToIntent(Context context, String subject,       String sendTo, boolean includeDebug) {     Uri uri = Uri.parse("mailto:" + sendTo);     Intent msg = new Intent(Intent.ACTION_SENDTO, uri);     msg.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);     StringBuilder body = new StringBuilder();     if (includeDebug) {       body.append(String.format(           "\n\n----------\nSysinfo - %s\nModel: %s\n\n",           Build.FINGERPRINT, Build.MODEL));       // body.append(String.format("\n\nBrand: %s\n\n", Build.BRAND));       body.append(String.format("%s config -\n", subject));       // Add locale info       body.append(String.format("locale: %s\n", context.getResources()           .getConfiguration().locale.getDisplayName()));     }     msg.putExtra(Intent.EXTRA_EMAIL, sendTo);     msg.putExtra(Intent.EXTRA_SUBJECT, subject);     msg.putExtra(Intent.EXTRA_TEXT, body.toString());     context.startActivity(msg);   }    }