Android Emulator 4.x API 16 Keyboard Issue

I was working on an android issue today where I wanted to use an emulator with no keyboard present. I tried creating a few different versions using API Level 16 4.0.3, and could get no keyboard present by editing the AVD in the Android Virtual Device Manager. After several attempts (and hey, this thing starts so darn fast each time you edit it) I was ready to quit trying. In other versions the on screen keyboard is launched when you tap the EditText, but for some reason all I would get in the latest emulator is the “Select Input Method” notification in the shade… not a keyboard even if I messed with the input settings.

Turns out the key is to add the Keyboard support = No to your AVD and then when you launch it, choose wipe user data. Ah, secret incantation that now exists that didn’t before! Thanks!

Android Shared Preferences Backed Up

I have been looking around for some way to back up the preferences in my Android app – just a simple serialization of the SharedPreferences object. Here are some code snips from my backup object that allowed me to get the job done:

private void importSharedPreferences()
{
  SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
  File myPath = new File(EXPORT_FILE_PATH);
  File myFile = new File(myPath, PREFS_FILE_NAME);
  if(myFile.exists())
	{
		BufferedReader i = new BufferedReader(new InputStreamReader(new FileInputStream(EXPORT_FILE_PATH + PREFS_FILE_NAME), "UTF8"));
		String line;

		while ((line = i.readLine()) != null)
		{
				String[] pair = line.split(":");

				SharedPreferences.Editor prefEdit = prefs.edit();

				if(pair[2].indexOf("Boolean")>-1)
				{
					prefEdit.putBoolean(pair[0], Boolean.parseBoolean(pair[1]));
				}
				else if(pair[2].indexOf("Integer")>-1)
				{
					prefEdit.putInt(pair[0], Integer.parseInt(pair[1]));
				}
				else if(pair[2].indexOf("Float")>-1)
				{
					prefEdit.putFloat(pair[0], Float.parseFloat(pair[1]));
				}
				else if(pair[2].indexOf("Long")>-1)
				{
					prefEdit.putLong(pair[0], Long.parseLong(pair[1]));
				}
				else if(pair[2].indexOf("String")>-1)
				{
					prefEdit.putString(pair[0], pair[1]);
				}

				prefEdit.commit();
			}
	}
}
public void exportSharedPreferences()
{
    SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);

    File myPath = new File(EXPORT_FILE_PATH);
    File myFile = new File(myPath, PREFS_FILE_NAME);

    FileWriter fw = new FileWriter(myFile);
    PrintWriter pw = new PrintWriter(fw);

    Map<String,?> prefsMap = prefs.getAll();

    for(Map.Entry<String,?> entry : prefsMap.entrySet())
    {
    		pw.println(entry.getKey() + ":" + entry.getValue().toString() + ":" + entry.getValue().getClass());
    }

    pw.close();
    fw.close();
}

I removed all of the error handling and might have messed up the formatting a bit, but you get the idea. Also, I plan on moving the serialization to a XML format in the next few days instead of the janky colon-separated bit. Hope this is helpful to you!

Netflix vs. Amazon Prime Instant Video

Netflix is about to get pretty expensive on 9/1/2011 and I’ve been searching for some alternatives and Amazon Prime is back in the picture.

Amazon Prime Instant Video has seamless Xbox extender integration that allows you to play movies instantly on the Xbox. Just tried it. Movie was 2% downloaded, and it said ready to watch. Walked to living room, started Xbox and was watching a high quality (no variable rate Netflix stutter or mice teeth) a minute later. The only install was a Amazon Unbox service that runs on the PC that automatically starts downloading anything you order (which is free with prime) even when the order comes from another device – say your mobile. Amazon quality is roughly similar to a DVD (when taking into account their advanced encoding vs. DVD – so a tie with Netflix DVD’s at home) and certainly better than some of those lower Netflix streaming rates for instant.

I have a pretty heavy Netflix account (3 d’s at a time) that goes to over $25/mo in September. Even if I put the Netflix account on hold for 3 months and “get by” with Prime, it pays for Prime for the year. One thing that complicates that though is a couple of kids in College that are using Netflix, and Prime extended family members only receive shipping benefits – not video. Sticking with the Netflix account but dropping to the $8 streaming only version may be the way to go there.

What about selection? Prime is currently saying 6000 instant videos available, and Netflix says 70,000. OK, that one certainly goes to Netflix. But I took a look at what I have watched recently and found that most of it was available on Prime, but the obscure stuff only on Netflix.

So, it looks like I’m going to have to switch in the next few weeks, Amazon Prime has my vote. I can live with the selection loss while a Netflix reduction happily pays for my Prime account chock full of 2 day shipping and free video.

FORFILES to find and delete files older than n days

Here is a quick tip for finding and deleting files that are older than some number of days.  I had been using a .bat file to purge a directory of log files that tended to fill up a drive quickly on a weekly basis when I ran accross the handy FORFILES command.  Using this command I can choose to only delete files older than n days (in this example, 10).

Here is the code:

FORFILES -p “C:\logfiles” -s -m *.* -d -10 /C “cmd /c del @PATH”

A good idea is to use an echo command to debug your .bat file first to make sure you are picking up the right set of files like this:

FORFILES -p “C:\logfiles” -s -m *.* -d -10 /C “cmd /c echo @PATH”

Obviously deleting files is not the only useful thing you can accomplish with FORFILES, so it’s up to your imagination on what you can do with the /C parameter.  Check out FORFILES /? for a listing of all the params available for the command.

The command was installed on the Server 2008 machine I was using, but not on the XP install I had on my laptop, but you can grab the .exe here ftp://ftp.microsoft.com/ResKit/y2kfix/x86/ and throw it in your system32 dir for use anywhere.

Android: Google Please Fix Emulator

O.K., so it’s not completely broken, but the Android emulator is about the worst thing the whole Android development platform has going for it. Sure, I get it that it is hard to write code that is emulating a completely different hardware architecture. I know that a lot of things have to be considered – I mean the phone is running a Linux variant underneath the covers and it takes some tricks to pretend to have file systems, keyboards, speakers, and microphones – not to mention the radios, orientation sensors, NFC chips, and other gizmos.

What I just don’t get though is why my 6 core, 16 GB dev box with dedicated video can’t emulate what my poor little G1 (and all of it’s Nexii brethren on my desk) does without a twitch. (OK, I’ll give it to you, the G1 kinda twitches….)

I told an interested Dev who has no device the other day to forget it. Go elsewhere until you get one: it’s just an exercise in frustration. It will start out great, and deteriorate into a mess on everything but the most simple of apps. The platform has so much going for it, the emulator is like the dirty little secret nobody talks about. Locked in the back closet, we all sweat just thinking of the use case our handset debugging will fail us like complex database issues.

But really. Someone at Google has to put this at the top of the old //TODO list. Hammer out a new emulator and make it start without lag, respond like it’s a real device. Until this is done, I will be sitting with iOS devs hoping they don’t bring this ugly reality up. And then I will laugh at them, and their toy OS. And then I will launch the emulator. And then I will go see if something in the garage needs to be bolted or riveted or something.

ToMarket HandyShopper Converter tool available

Over on my App website for ToMarket I have a utility that can help HandyShopper users convert their PDB files to ToMarket CSV files so that they can import them into their shiny Android phones, finally ridding themselves of the Palm legacy. (Hey, I loved it at the time too 😉 ) So go check it out if you have Handy Shopper roots and want to move into the 10’s with ToMarket Grocery Shopping:

http://www.tomarketweb.com/dnn/GettingStarted/ConvertingFromHandyShopper.aspx

Hello again…

Well, AllredHouse.com has seen it’s fair share of changes over the years and today is another example – Diane is taking it over and blogging her heart out.  Check it out, she is really quite good!  7 years ago I started this site to share our family pics and goings on. Today I’m starting over, focusing on blogging my tech rants, learnings, and the occasional fishing story here at HeadRevision.com.

Welcome to HeadRevision. My name is Mike Allred and I hope you find something interesting or amusing here.