Beginner

[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!

Register for YouTube API use

This post walks you through registering for the YouTube API. This is necessary if you want to upload / download videos from YouTube using OAuth.
Another way to think of registering is that, it creates a server side representation of your android app that you are going to create, so that Google can recognise your app and allow it to talk to YouTube.

First off you need to have created the skeleton of your application you have in mind, because you’ll need your package name. Once you have the package name go here:

https://developers.google.com/youtube/2.0/developers_guide_protocol_oauth2#OAuth2_Register

Follow the steps on the YouTube website, however at step 5 choose “installed application” NOT “web application”.

Then installed application type “Android”

That then gets you to this page:

Insert your package name. This is found in your AndroidManifest i.e. com.blundell.tutorial

You then need your SHA1 fingerprint. You create this using your keystore. You can use the debug keystore, don’t forget to update this when you release (using your live keystore). Run this command against your keystore and you should get the SHA1:

keytool -exportcert -alias androiddebugkey -keystore path-to-debug-or-production-keystore -list -v

Click Create Client ID and your done! You’ve now created an OAuth Client for the Google APIs that you can use with YouTube, you’ll want to bookmark this page as it contains the client IDs and redirect URLs that you use with the OAuth API.

Once you have done this you can go on to code an Android application to use the Android API. Tutorial Here