ACL_CONNECTED / ACL_DISCONNECTED not starting broadcast receiver in Android 3.1?

4,092 views
Skip to first unread message

hjellinek

unread,
Jun 29, 2011, 6:06:02 PM6/29/11
to android-...@googlegroups.com
I'm suffering from a bit of jetlag, so maybe I'm missing something that should be obvious here.

I've got a broadcast receiver that's supposed to run on Bluetooth headset connect and disconnect.  It works fine on an Android 2.3 device, but not a 3.1 device (Motorola Xoom).  The debug messages "OnReceive", "** CONNECTED" and "** DISCONNECTED" never appear in the log.

AndroidManifest.xml:

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <application android:label="@string/service_name" android:debuggable="true">
        <receiver android:name=".HeadsetReceiver">
            <intent-filter>
                <action android:name="android.bluetooth.device.action.ACL_CONNECTED"/>
                <action android:name="android.bluetooth.device.action.ACL_DISCONNECTED"/>
            </intent-filter>
        </receiver>
    </application>
    ...

The receiver looks like this:

public class HeadsetReceiver extends BroadcastReceiver {
    ...
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "OnReceive");
        String action = intent.getAction();

        if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
            Log.i(TAG, "** CONNECTED");
        } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
            Log.i(TAG, "** DISCONNECTED");
        } else {
            ...
        }
        ...
    }
....

Have I found a bug in 3.1, or do I simply need more sleep?  Thanks.

Adam Jiang

unread,
Jun 29, 2011, 10:54:07 PM6/29/11
to android-...@googlegroups.com

You may have to listen the event

android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED

/Adam
>
> --
> You received this message because you are subscribed to the Google Groups "android-platform" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/android-platform/-/6rEshCix6usJ.
> To post to this group, send email to android-...@googlegroups.com.
> To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.
>

Thomas Economous

unread,
Jun 30, 2011, 1:37:58 PM6/30/11
to android-platform
I have run into a problem on 3.1 that may be related. When my app
installs it's broadcast receiver does not seem to be immediately
active. I have to launch my app once before the broadcast receiver
starts working.

In 2.2 the broadcast receiver worked immediately after install. Maybe
this is the same thing you are seeing? Does your receiver work after
launching the app once?

Herb Jellinek

unread,
Jun 30, 2011, 2:48:07 PM6/30/11
to android-...@googlegroups.com
Hello Thomas,
    I added an activity to my app, which formerly had none (it's intended to run in the background), launched it, and connected my headset.  And voila, it works.  And the registration even persists across rebooting the device.
    I don't think this reflects an intentional change to the Android API, but rather a major regression.  I hope they fix it soon.
    Thanks SO much for the tip.

        Herb

Christopher Tate

unread,
Jun 30, 2011, 4:53:54 PM6/30/11
to android-...@googlegroups.com
On Thu, Jun 30, 2011 at 11:48 AM, Herb Jellinek <herb.j...@gmail.com> wrote:
> Hello Thomas,
>     I added an activity to my app, which formerly had none (it's intended to
> run in the background), launched it, and connected my headset.  And voila,
> it works.  And the registration even persists across rebooting the device.
>     I don't think this reflects an intentional change to the Android API,
> but rather a major regression.  I hope they fix it soon.

This was indeed a deliberate policy change: now, downloaded
applications are not active until they have been explicitly launched
by the user.

(Note that in general, it has never been the case that Android
promised that newly-installed applications could autorun.)

--
christopher tate
android framework engineer

>     Thanks SO much for the tip.
>
>         Herb
>
> On Thu, Jun 30, 2011 at 10:37 AM, Thomas Economous <econ...@gmail.com>
> wrote:
>>
>> I have run into a problem on 3.1 that may be related. When my app
>> installs it's broadcast receiver does not seem to be immediately
>> active. I have to launch my app once before the broadcast receiver
>> starts working.
>>
>> In 2.2 the broadcast receiver worked immediately after install. Maybe
>> this is the same thing you are seeing? Does your receiver work after
>> launching the app once?
>

> --
> You received this message because you are subscribed to the Google Groups
> "android-platform" group.

hjellinek

unread,
Jun 30, 2011, 5:25:38 PM6/30/11
to android-...@googlegroups.com
That it's not a regression restores my faith in the Android engineering team.

(If this change was announced somewhere, it should have been in a larger font. :-))

        Herb


Thomas Economous

unread,
Jul 1, 2011, 11:21:58 PM7/1/11
to android-...@googlegroups.com
Christopher,

Thanks for confirming that this is a deliberate change in 3.1. I am fairly new to android development. What is a good android reference for changes like this?

Thanks,
Tom

Reply all
Reply to author
Forward
0 new messages