[TUT] Email Feedback from Users (device information)

I recently updated my McDonalds Calories application and improved the feedback facilities. Whilst I was doing this I realised it would be good to do in all of my apps and therefore wrote this utility class just for the purpose.
The idea is to gain more information about the users devices when they send you (dare I say it *complaint*) feedback about the app functionality.

This email will now include by default a good amount of information about the device. Including the Android version and make, model, screen density of the device.
The email automatically sets the subject to the name of the application and appends the version of the running app to the end.

Like so:

Email Feedback

I made it nice and easy I can now just include my FeedbackUtils class and with one line get a nice feedback email with a lot of information to help my deliteful users!

FeedbackUtils.askForFeedback(context);

And here is the code.

FeedbackUtils.java


import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;

public class FeedbackUtils {
	private static final String FEEDBACK_CHOOSER_TITLE = "Feedback. Have we forgotten something?";
	private static final String EMAIL_ADDRESS = "support@blundell-apps.com";

	public static void askForFeedback(Context context) {
		final Intent emailIntent = new Intent(Intent.ACTION_SEND);
		emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		emailIntent.setType("plain/text");
		emailIntent.putExtra(Intent.EXTRA_EMAIL, getFeedbackEmailAddress());
		emailIntent.putExtra(Intent.EXTRA_SUBJECT, getFeedbackEmailSubject(context));
		emailIntent.putExtra(Intent.EXTRA_TEXT, getFeedbackDeviceInformation(context));
		context.startActivity(Intent.createChooser(emailIntent, FEEDBACK_CHOOSER_TITLE));
	}

	private static String[] getFeedbackEmailAddress() {
		return new String[] { EMAIL_ADDRESS };
	}

	private static String getFeedbackEmailSubject(Context context) {
		return getApplicationName(context) + " Feedback v" + getAppVersion(context);
	}

	private static String getApplicationName(Context context) {
		return context.getString(context.getApplicationInfo().labelRes);
	}

	private static String getAppVersion(Context context) {
		try {
			return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
		} catch (NameNotFoundException e) {
			return "vX.XX";
		}
	}

	private static String getFeedbackDeviceInformation(Context context) {
		StringBuilder emailMessage = new StringBuilder();
		emailMessage.append("\n\n_________________");
		emailMessage.append("\n\nDevice info:\n\n");
		emailMessage.append(getHandsetInformation(context));
		emailMessage.append("\nPlease leave this data in the email to help with app issues and write above or below here. \n\n");
		emailMessage.append("_________________\n\n");
		return emailMessage.toString();
	}

	private static String getHandsetInformation(Context context) {
		StringBuilder handsetInfoBuilder = new StringBuilder();
		handsetInfoBuilder.append("Bootloader: " + Build.BOOTLOADER);
		handsetInfoBuilder.append("\nBrand: " + Build.BRAND);
		handsetInfoBuilder.append("\nDevice: " + Build.DEVICE);
		handsetInfoBuilder.append("\nManufacturer: " + Build.MANUFACTURER);
		handsetInfoBuilder.append("\nModel: " + Build.MODEL);
		handsetInfoBuilder.append("\nScreen Density: " + getDeviceDensity(context));
		handsetInfoBuilder.append("\nVersion SDK int: " + Build.VERSION.SDK_INT);
		handsetInfoBuilder.append("\nVersion codename: " + Build.VERSION.CODENAME);
		handsetInfoBuilder.append("\nVersion incremental: " + Build.VERSION.INCREMENTAL);
		handsetInfoBuilder.append("\n");
		return handsetInfoBuilder.toString();
	}

	private static float getDeviceDensity(Context context) {
		return context.getResources().getDisplayMetrics().density;
	}
}

Enjoy!

3 thoughts on “[TUT] Email Feedback from Users (device information)

  1. Hi Blundell Team,

    My name is Anuj Agarwal. I’m Founder of Feedspot.

    I would like to personally congratulate you as your blog Blundell | Android Developer Tutorials has been selected by our panelist as one of the Top 40 Android Developer Blogs on the web.

    I personally give you a high-five and want to thank you for your contribution to this world. This is the most comprehensive list of Top 40 Android Developer Blogs on the internet and I’m honored to have you as part of this!

    Also, you have the honor of displaying the badge on your blog.

    Best,
    Anuj

Comments are closed.