I don't mean to hijack this thread, but how do you import
android.bluetooth.BluetoothDevice on 1.x?


On Apr 4, 12:35 pm, DulcetTone <dulcett...@gmail.com> wrote:
> Ok... it's ugly.  Indeed, this was one of the things I found difficult
> to do in the same manner in Android 1.x and Android 2.x
>
> I actually found it difficult to have one app exercise both these
> interfaces, one of the several reasons I wish I had a separate app for
> 1.x vs 2.x  -- if you've not yet made a final choice there, split them
> up and you will be happier.
>
> In Android 1.x, this will do it, cribbed and reduced from Android
> source.
> I had to bring over a considerable portion of android.bluetoothto get
> this working.
>
> You would call the staticenable() function to do it:
>
> import android.bluetooth.BluetoothDevice;
> import android.content.Context;
>
> public class LocalBluetoothManager {
>
>     private static LocalBluetoothManager sSingleton;
>     /** Used when obtaining a reference to the singleton instance. */
>     private static Object INSTANCE_LOCK = new Object();
>
>     private boolean mInitialized;
>     private BluetoothDevice mManager;
>
>     public static booleanenable(Context context, boolean b) {
>
>         synchronized (INSTANCE_LOCK) {
>             if (sSingleton == null) {
>                 sSingleton = new LocalBluetoothManager();
>             }
>
>             if (!sSingleton.init(context)) {
>                 return false;
>             }
>             return b ? sSingleton.mManager.enable() :
> sSingleton.mManager.disable();
>         }
>
>     }
>
>     private boolean init(Context context) {
>         if (mInitialized) return true;
>         mInitialized = true;
>
>         mManager = (BluetoothDevice)
>             context.getSystemService("bluetooth"); //
> Context.BLUETOOTH_SERVICE);
>         if (mManager == null) {
>             return false;
>         }
>
>         return true;
>     }
>
> }
>
> In Android 2.x, it is simpler:
>
> import android.bluetooth.BluetoothAdapter;
> BluetoothAdapter adapt = BluetoothAdapter.getDefaultAdapter();
> adapt.enable(); // or adapt.disable();
>
> You MAY need to have these permissions in your manifest:
>
>     <uses-permission android:name="android.permission.BLUETOOTH" />
>     <uses-permission
> android:name="android.permission.BLUETOOTH_ADMIN" />
>
> Make sure you test on both Android 1.x and 2.x before going to Market.
>
> tone

-- 
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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to