Archives for category: Android

On the day I bought it, the quickly deepening love I felt for my new LG G3 was seriously dampened when I plugged it in to my computer. I had unlocked Developer options and enabled USB debugging only to enter the default Installer Mode. It all came back to me: the same USB mode-switching rigmarole with past Verizon LG devices.

Today, I varied my Google search and stumbled on the solution, no root required:

  1. Open the Dialer
  2. Dial ##3328873 and press Send
  3. Enter the service code: 000000
  4. Uncheck the Tool Launcher enable box
  5. Reboot the phone

Now when you plug in your phone, it should enter the last connection mode you selected—which, if you need USB debugging, will be Internet connection – Ethernet.

$ logout


We were having trouble POSTing emojis correctly on our app using RoboSpice, where each emoji or non-Latin character would render as Ÿ‰ð. We knew this wasn’t a server issue, as the iOS app wasn’t having problems. We were using a separate RestTemplate for this particular request, but it turned out we simply needed to provide charset=utf-8 as part of our Content-Type header:



After, based on this StackOverflow answer:

HttpHeaders headers = new HttpHeaders();
headers.set("Connection", "Close");
Charset utf8 = Charset.forName("UTF-8");
MediaType mediaType = new MediaType("application", "x-www-form-urlencoded", utf8);

There seems to be another way to continue using the APPLICATION_FORM_URLENCODED constant with the MediaType constructor while passing in the charset, but I couldn’t figure it out in 5 minutes from the documentation.

$ logout

Adding new image assets to our Android app is tedious. Since our designers target iOS first, there are a few things the Android team has to do when we get new graphics:

  1. Ensure graphics have valid file names (no hyphens, no unnecessary @2x in the name).
  2. Ensure similar graphics (e.g. icons in the drawer) are the same size.
  3. Provide the graphic at all possible densities.

I’ve created a script to speed up the renaming process. Before running it, I only copy the retina (…@2x…) graphics to my working directory, and then run it on my Mac or Linux machine:


# Standardizes image file names to be usable as Android resources.

# Make sure we have some files to rename before continuing
if [ -z "$1" ]; then
	echo "usage: file [file2...]"
	exit 1

for INFILE; do
	# Do the stuff
	if [ "$INFILE" != "${INFILE//-/_}" ]; then
		# Replace hyphens with underscores
		mv -i "$INFILE" "$NEWFILE"

	if [ "$NEWFILE" != "${NEWFILE//@2x/}" ]; then
		# Remove retina-ified filenames
		mv -i "$NEWFILE" "${NEWFILE//@2x/}"

	# Sanity check
	echo "Moved $INFILE to ${NEWFILE//@2x/}"

Also on GitHub.

This is useful for doing multiple images at once, e.g. icon-*.png, and, of course, it helps when you like the designer’s naming scheme.

$ logout

I was trying to add a custom font to the LunchTable app when an exception thrown by Typeface.createFromAsset gave me “Native typeface cannot be made.” For me, this was related to Gradle.

The solution was simple: I moved my assets folder directly under main, at the same level as java and res. It might not be necessary, but my .ttf file was in assets/fonts/, as well.

$ logout

There is an issue with the Sony Xperia Z (C6833) keyboard that causes any EditText using an InputFilter to misbehave. For example, typing h-e-l-l-o in one of these fields comes out as hhehelhellhello.

In order to keep my filtering functionality (I want to only allow alphanumeric characters), I removed my old code ( myText.setFilters(new InputFilter[] { ... }); ) and made a few simple changes to any EditTexts I need filtered so they look like this:


The android:digits property does the filtering here. Give it any and all valid characters you want to accept, and for extra credit, throw it in a string resource to reduce copy-and-paste errors.

If you’d like the “Next” button to show on your user’s keyboard for this field, android:imeOptions="actionNext" alone isn’t going to cut it—the android:digits property causes the keyboard to show an Enter key on every device I tested, so throw in android:singleLine="true" to fix it.

$ logout

Sometimes error messages don’t really do their job and tell you how to rectify them, like this one I found today in Android Studio (v0.4.5). While attempting to add a page indicator for my ViewPager, I got “CirclePageIndicator is not allowed here.”

Way to be ambiguous...

As it turns out, this is less about Mama Android telling you where to put your controls, and more about using the correct namespace when adding controls (I had only copied over this class, not the whole project).

Mind your namespaces!

$ logout

After creating a new project in Android Studio 0.3.1 utilizing Gradle, opening the project on a new machine gave me a few problems.

First, I got: Gradle could not resolve all dependencies.

To fix this, I opened the SDK Manager and downloaded the Android Support Library, since isn’t in Maven Central.

Next, I got: Could not execute build using gradle installation.

To fix this, I opened a terminal and ran gradle build. Ubuntu informed me it wasn’t installed, so I:

  1. downloaded it
  2. moved it to /opt/gradle
  3. went to Settings > Gradle in Android Studio
  4. under Project-level settings, selected Use local gradle distribution
  5. changed both Gradle home and Service directory path to /opt/gradle
  6. restarted Android Studio

And everything worked!

$ logout