Hi,

I'm implementing Bluetooth support on my application, which is
compatible with Android 1.6 (and must remain since in Brazil we still
have those devices running out).

By reading this article:
http://developer.android.com/resources/articles/backward-compatibility.html

I found an easy way that allow you to create classes that can be used
in new and old devices.

The idea is the creation of a DUMB class, that would work in devices
that are not compatible, and an IMPLementation class that extends the
DUMB class and would work on devices that are compatible.

So, this is the dumb class:

public class Level5
{
   public static Level5 instance = android.os.Build.VERSION.SDK_INT >=
5 ? new Level5Impl() : new Level5();

   public boolean btIsSupported()
   {
      return false;
   }
}

And here the implementation class:

public class Level5Impl extends Level5
{
   public boolean btIsSupported()
   {
      bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
      return bluetoothAdapter != null;
   }
}

Then, you can call:

Level5.instance.btIsSupported();

All public fields that are used inside Level5Impl must be declared
inside Level5, and all public methods must be declared in Level5 too,
so they are overriden in Level5Impl.

Hope this helps,

      Guilherme C. Hazan (guich)
      www.totalcross.com

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to