Hi Nick,

Thanks for your reply.

To turn on and off bluetooth, I use the following code from Android
source code,

        if (!System.putInt(etContentResolver(), System.BLUETOOTH_ON, state))
{
                Log.d(LOG_TAG, String.format("set bluetooth state to %d failed",
state));
                return -1;
        }
        String action = state == 1 ?
                        ENABLED_ACTION : DISABLED_ACTION;
        Intent intent = new Intent(action);
        //sendBroadcast(intent, BLUETOOTH_PERM);
        sendBroadcast(intent);

and it works well, I could see the bt icon on the top the phone. And
the receiver is also from source code, what confuse me is why the
receiver doesn't work while enabling/disabling Bt works well since
they comes from same origination?

Thanks,

Stanley

On Feb 19, 3:44 pm, Nick Pelly <[email protected]> wrote:
> There is no way to turn on and off bluetooth through the official SDK right 
> now.
>
> Some apps have found ways to do this using hidden API's, and they are
> going to break when cupcake is released.
>
> Nick
>
> On Wed, Feb 18, 2009 at 10:47 PM, Stanley.lei <[email protected]> 
> wrote:
>
> > Hi,
>
> > I wanna write an app to enable and disable the Bluetooth device
> > synchronized. Referring the Android source code, I registered
> > following receiver to receive the bluetooth state change event:
>
> > private static final String EXTENDED_BLUETOOTH_STATE_CHANGED_ACTION =
>
> > "com.android.settings.bluetooth.intent.action.EXTENDED_BLUETOOTH_STATE_CHANGED";
>
> >    private final BroadcastReceiver mReceiver = new BroadcastReceiver
> > () {
> >       �...@override
> >        public void onReceive(Context context, Intent intent) {
> >            String action = intent.getAction();
> >            if (action.equals
> > (EXTENDED_BLUETOOTH_STATE_CHANGED_ACTION)) {
> >                Log.d(LOG_TAG, "bt state changed");
> >                ContentResolver resolver = context.getContentResolver
> > ();
>
> >                // If bluetooth is currently expected to be on, then
> > enable or disable bluetooth
> >                if (Settings.System.getInt(resolver,
> > Settings.System.BLUETOOTH_ON, 0) > 0) {
> >                    // do sth....
> >                } else {
> >                    // do sth...
> >                }
> >            }
> >        }
> >  };
>
> > IntentFilter filter = new IntentFilter(
> >                EXTENDED_BLUETOOTH_STATE_CHANGED_ACTION);
> > registerReceiver(mReceiver, filter);
>
> > But it doesn't work. Although the BT status has been changed (the icon
> > of BT has been appeared or disappeared), the receiver could not
> > receive nothing.
>
> > Could you give me any suggestion on this issue? It is tearing out my
> > hair.
>
> > Any reply will be appreciated.
>
> > Thanks,
>
> > Stanley
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to