MonoDroid: How to determine if you are on a phone or tablet

In a recent Android based mobile application using Mono, our customer requirements dictated two sets of screen layouts: one for Android phones and one for Android tablets.

Easy right?

Well… No.  The requirement statement “detect if the device is a tablet or phone using MonoDroid and display the appropriate layout” turned out to not be as trivial as we originally suspected.

A quick Google search turned up several solutions using screen size and density to determine the answer to the phone vs. tablet question.  While workable, these solutions were far from fool proof due to the vast array of sizes and densities available on various Android devices.

Ugh.

During an offsite Red Solo cup session, the answer occurred to one of our senior developers:  Ask about IMEI!  If the device has an IMEI, its gotta be a phone (or a tablet with suspiciously phone like qualities).

Our Solution
A property exposed on a helper class which probes the IMEI and determines phone vs. tablet.

EDIT 02/27/2012: Code updated to reflect API support for 4G phones

public bool IsPhone
{
  get
  {
    return ((this.GetSystemService(Context.TelephonyService) as
                TelephonyManager).PhoneType != PhoneType.None);

   }
}

 

Quick, simple, solved!

Avast! Business Protection Plus: Administration console will not open in browser.

Here at AIS, we just completed a test install of Avast’s new “for business” centrally managed Anti-virus software (see this link for full details).  The installation went smoothly until we attempted to launch the Silverlight based administration console.  We expected to be greeted by a nice, new, shiny console with all the bells and whistles.  What we got was…. nothing.

Our Environment

  • Windows server 2008 R2
  • Avast! Business Protection Plus (version 1.1.6164)
  • Standard install of Avast! Business Protection Plus
    (All defaults accepted except the SQL Server default.  We already had a SQL instance prepared and ready to go)
  • Test client running Windows 7

Symptoms

Using a default install, the administration console should be available at the following URL

http://ServerUNCGoesHere/Avast/

In theory, this link will redirect you to the Avast! administration console on port 8732 using ssl.  We attempt to launch the administration console from our Windows 7 PC using IE9.  After 1 – 2 minutes, we received an error simple stating

Internet explorer cannot display the webpage

Helpful….

Root Cause
It didn’t take us long to figure out we had a firewall issue.  Port 8732 was nonresponsive to traffic.  A quick look at the firewall settings demonstrated the Avast! installer had modified the firewall rules.  Two new rules had been added, one rule each for UDP and TCP connections referencing the program
C:Program FilesAVAST SoftwareAdministration ConsoleAvast.Sbc.Server.exe

That should work…  but Windows Firewall was not in agreement.

We did not spend the time to figure out why the firewall association to the service level application was not working.  Our guess is Avast! is using some behind the scenes redirects which confuse the firewall.

Solution
We need to add port level firewall settings for Avast!

  1. Open Windows Firewall with Advanced Security on the server Avast! was installed on
  2. Highlight the Inbound Rules section
  3. From the menu select MENU: Action –> New Rule
    This will launch the new rule wizard
  4. Under Rule Type, select Port
    image
  5. Under Protocol and Ports, enter the specific ports 8731, 8732, and 25322
    NOTE: Your ports maybe different if you did not use the installation defaults
    image
  6. Under Action, select Allow the connection
    image
  7. Under profile, select the appropriate profile for you installation
    (In our environment, we selected “Domain” to reflection our network domain)
    image
  8. Under Name, give your rule a new name
    We recommend “avast! Administration Console (ports)” to prevent any confusion

 

That’s it!
We were now greeted with a nice, new, shiny console with all the bells and whistles.

Monotouch iPhone – Showing activity to the end (or how to create an iPhone wait cursor)

One of AIS’s recent projects involved development of an iPhone application using MonoTouch. This application made significant use of web services, some of which could take 10’s of seconds to return (Yes, we were moving a lot of data for this particular application… there is just no easy way to deal with “historical data”).

Rather than just locking the UI for the duration of the activity, we wanted to display a user notification that something was actually happening in the background. In addition, we wanted to disable the UI so the user did not inadvertently believe they could tap anything.

Our goals:

1. Display a “long running operation” notification to the user

2. Lock the primary UI to prevent unwanted unexpected user interactions

3. The component must be reusable

To accomplish this feat of programming, we decided to use a UIAlertView with a UIActivityIndicatorView on it. We created the ActivityAlertView class to manage this for us. It allows you to use it in one of 2 ways:

  1. In a using statement. This will display the ActivityAlertView for the duration that the using statement is in scope:
  2. using(ActivityAlertView alert
              = new ActivityAlertView("Logging in, Please wait"))
    {
          //Code to do while ActivityAlertView is displayed to user
    }

  3. Normal instantiation
  4. ActivityAlertView alert = new ActivityAlertView;
    alert.Show("Logging in, Please wait");
    //Code to do while ActivityAlertView is displayed to user
    alert.Dismiss();

Here are a few screenshots of the attached demo project.

imageimageimage
(Click image to enlarge)

Download the sample project and source code from this link