Decided to spend an evening updating one of my popular (18,000 downloads) Android applications to support the shiny new Honeycomb holo layout and theme.
I initially decided to do this as a separate app, as there was different app code as well as the layout. This was fine, got my app working and uploaded it to the Android marketplace, and used the new side-by-side feature, where you can have different APK’s supporting different devices on the same marketplace listing, and it will “just work(tm)”. So I created a manifest.xml for my tablet version to only support xlarge screens, the smartphone app supporting everything else.
I used the following in the manifest:
<compatible-screens>
<!– all small size screens –>
<screen android:screenSize=”small” android:screenDensity=”ldpi” />
<screen android:screenSize=”small” android:screenDensity=”mdpi” />
<screen android:screenSize=”small” android:screenDensity=”hdpi” />
<screen android:screenSize=”small” android:screenDensity=”xhdpi” />
<!– all normal size screens –>
<screen android:screenSize=”normal” android:screenDensity=”ldpi” />
<screen android:screenSize=”normal” android:screenDensity=”mdpi” />
<screen android:screenSize=”normal” android:screenDensity=”hdpi” />
<screen android:screenSize=”normal” android:screenDensity=”xhdpi” />
<!– all large size screens –>
<screen android:screenSize=”large” android:screenDensity=”ldpi” />
<screen android:screenSize=”large” android:screenDensity=”mdpi” />
<screen android:screenSize=”large” android:screenDensity=”hdpi” />
<screen android:screenSize=”large” android:screenDensity=”xhdpi” />
</compatible-screens>
Everything seemed fine, but when I checked the Android marketplace compatibility report, it was telling me my app was not compatible with alot of devices (for reasons unknown), and there was no logic to the devices that it claimed were OK, those that it claimed were”t and no relation to reality either (as it claimed HTC Sensation was incompatible, yet a HTC Sensation owner checked for me, and my app was all present and correct).
Anyway back to the drawingboard. I decided that a single APK was the way to go, and as it turned out, whilst a little wasteful, it worked very well (my app is still only 200kb). Here is what I did.
- Took the res, layout and drawable directories in my tablet app and put a -v11 sufix on the to signify Honeycomb onwards, and then copied them into my smartphone app
- Added the new activites to a merged Manifest.xml
- Renamed my original main activites to TabletActivity and PhoneActivity
- created a new startup activity with the following logic in it.
public class ActivitySelector extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);Intent intent;
if (isTablet())
{
intent = new Intent(this, TabletActivity.class);
}
else
{
intent = new Intent(this, PhoneActivity.class);
}startActivity(intent);
finish();
}public boolean isTablet()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
{
return (getResources().getConfiguration().smallestScreenWidthDp >= 600);
}return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
}
This was the main nuts of the change, and aside from some small amout of other refactoring, it was a job done!. Now my app on the marketplace is showing compatable with pretty much everything Android 1.6+ including Honeycomb tablets, and it should also work for Android 4.0 (Icecream Sandwhich). There might be better ways to do this, but this is simple and effective and follows the KISS principle.
If anyone bumps into Steve Jobs, tell him that his claims of Android fragmentation are utter bullshit (just like his overpriced products). Cheers.


