Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

android - Broadcast receiver not working in ICS if the app is not started atleast once

This question has been asked few times in stack overflow, but no solution, yet. I have a broadcast receiver for for receiving USB connected action.The broadcast receiver responsibility is , if I get the intent start my application.In the manifest file I have added the receiver . I have the same logic working in GingerBread, but I ICS its not working. Many questions like , broadcast-not-invoking

1: Android Boot-Up BroadCast Not invoking and broadcastreciever-not-working

If I start my app manually once, then from next time on-wards when USB is connected my App starts automatically. tries to answer the same question but no answer. Is there any solution for this in ICS?

This my receiver

        <receiver android:name="com.test.MyReceiver">
                <intent-filter>
                    <action android:name="android.hardware.usb.action.USB_STATE" />
                    <action android:name="android.net.wifi.STATE_CHANGE" />
            <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
                </intent-filter>
            </receiver>
    and this is my class
    public class MyReceiver extends BroadcastReceiver {
    .
    .
    .

  public void onReceive(Context context, Intent intent) {
.

Am i wrong anywhere?

Thanks in advance --Kozlov

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Is there any solution for this in ICS?

It is working correctly. As of Android 3.1, no BroadcastReceiver will work until the user has manually launched an activity. I blogged about this eight months ago.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...