Friday, September 18, 2009

Calling my app from a MIME type in Android

It seems like this is something that people might want to be able to easily do. But, surprisingly enough when I google this, I get a lot of posts with people saying, "How do I have my app get called when the browser reads a certain MIME type?"

Here is your answer.

It is really fairly simple. In fact, most of what you need to know is included in the Notepad sample app on the Android SDK site! But, there are some minor details missing.


If you follow what is available on the Android SDK site, you would add a new <intent-filter> to your manifest, that would look something like this :

<intent-filter>
<action:name="android.intent.action.VIEW" />
<category:name="android.intent.category.DEFAULT" />
<data:mimetype="testtype/testtype" />
</intent-filter>

Then, you just need to have a web server that can serve up our "testtype/testtype" MIME type to make it work, right?

Well, to test that theory, I hacked up this cute little piece of PHP, and stuck it on a local web server :

<?php

header("Content-type: testtype/testtype");

echo("Testing!");
?>

Note : Your web server will have to be able to run PHP for this to work! You are on your own to figure that out.


I named this PHP script test.php, and dropped it in the root share for my web server. Then, I pulled up the Android browser, and went to the web page : <myserver>/test.php .

What happened, was underwhelming to say the least. The phone downloaded a file called test.php. If I then tapped on the file name, it would start my application. So, I knew I was close.


After more digging around, I discovered the magical incantation. The MIME type line needs to know that we want to look specifically for things downloaded via http. So, I made a small change to my manifest file. The MIME type line now looks like this :

<data:mimetype="testtype/testtype" scheme="http">



Then, I ran the same test again, and my application was now loaded when I attempted to pull up the .php script that issued the testtype MIME type.

Monday, September 7, 2009

Its ALIVE!!!!

Well, I just dropped my first Android application out on the Marketplace. "Movie Track" was my first attempt at an Android program, and has been really useful to me. I only put it out there in hopes that others might also find it useful. When it comes right down to it, the app isn't super flashy, and isn't something you would show your friends to convince them how cool the android is. Instead, it is the first of hopefully many programs I will be releasing to the marketplace.

So, if you happen to have a MythTV box, and a lot of movies, give my app a try!

Tuesday, September 1, 2009

Side-by-side.. The lazy Android method..

One of the coolest things that the Android has out of the box is the "side-by-side" screens that make up the home screen. For a project that I am working on, it seems like this type of layout would be really useful. So, I set out trying to find out how to do it.

A bit of Googling found this article. I grabbed the code, threw it in Eclipse, and tried to make it work. Along the way Eclipse pointed out to me that the AbsoluteLayout has been deprecated. Because of that, I decided not to spend a bunch of time trying to figure out why my first few attempts using the code failed.

A bit more looking around found the HorizontalScrollView class. Using that class, along with a little creativity allowed me to make something that let me have a single really wide screen. But, what I wanted was something that snapped to the left or right to keep a single "screen" in focus.

The previously mentioned article had the code I needed to catch the events of a user dragging their finger across the screen. So, all I had to do was figure out how to put it all together. The end result is the HorizTwo class, which creates two "virtual screens" that snap to the left and right based on how far the user drags.

You can find the code on my download page here.

This code is really simple, and makes some potentially bad assumptions about the size and format of an Android screen. But, it seems like a good place for someone to start if they wanted to be able to have "side-by-side" screens.

There is one key point that may not jump out at you when you first look at the code. When you create the layouts that you want to show in each of the virtual screens, you need to give the layout an id. Normally, the Eclipse tools won't do this, so you will have to manually hunt the id field down, and set it. If you don't do this, you may not get the results you want.