Set up email Intent for feedback - Android Intent

Android examples for Intent:Send Email

Description

Set up email Intent for feedback

Demo Code


//package com.java2s;

import java.util.List;

import android.content.Context;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.content.pm.ResolveInfo;

import android.widget.Toast;

public class Main {
    public static void feedback(Context context, String feedBackEmailId,
            String emailSubject, String msg) {

        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { feedBackEmailId });
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
        emailIntent.putExtra(Intent.EXTRA_TEXT, msg);
        emailIntent.setType("message/rfc822");
        emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        if (isIntentAvailable(context, emailIntent)) {
            context.startActivity(emailIntent);
        } else {/* www  .  j  av a 2  s  . co m*/
            Toast.makeText(context, "No Email Application Found", Toast.LENGTH_LONG).show();
        }
    }

    public static boolean isIntentAvailable(Context ctx, Intent in) {
        PackageManager packageManager = ctx.getPackageManager();
        List<ResolveInfo> activities = packageManager.queryIntentActivities(in, 0);
        return (activities == null) ? false : (activities.size() > 0);
    }
}

Related Tutorials