1

我的清单中有一个像这样注册的 BroadcastReceiver:

<receiver
        android:name="xxx.xxx.xxx.LaunchReceiver"
        android:enabled="true"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        </intent-filter>
        <intent-filter>
            <action android:name="xxx.xxx.xxx.xxx.ACTION_PULSE_SERVER_ALARM" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />
        </intent-filter>
    </receiver>

问题是它有时会无缘无故地连续触发 6-7 次。有没有办法检查到底是什么触发了它?

我试过了

Log.d("LaunchReceiver", "intent.getAction(): " + intent.getAction());    
Log.d("LaunchReceiver", "intent.getDataString(): " + intent.getDataString());
Log.d("LaunchReceiver", "intent.getType(): " + intent.getType());

但它们总是空的。

我也试过

NetworkInfo ni = cnnxManager.getActiveNetworkInfo();

Log.d("LaunchReceiver", "ni.getTypeName(): " + ni.getTypeName());
Log.d("LaunchReceiver", "ni.getExtraInfo(): " + ni.getExtraInfo());
Log.d("LaunchReceiver", "ni.getState().name(): " + ni.getState().name());
Log.d("LaunchReceiver", "ni.isFailover(): " + ni.isFailover());

但他们不会改变...

任何帮助将不胜感激。

谢谢

编辑:它似乎与网络状态变化有关。当我刚刚从移动网络切换到wifi时,它触发了4次

intent.getAction(): android.net.conn.CONNECTIVITY_CHANGE

然后无缘无故又触发了一次,一共触发了5次。

Edit2:当从 wifi 切换到移动网络时,我得到了很多这样的信息:

08-02 16:45:18.074: D/libc(24471): [NET]_files_getaddrinfo+
08-02 16:45:18.074: D/libc(24471): [NET]_files_getaddrinfo-,1
08-02 16:45:18.074: D/libc(24471): [NET]_dns_getaddrinfo+
08-02 16:45:18.074: D/libc(24471): [NET]_dns_getaddrinfo-,3
08-02 16:45:18.074: D/libc(24471): [NET] getaddrinfo-exit,err=7
08-02 16:45:18.074: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.074: D/libc(24471): [NET] ht 0x66772e776f6c66
08-02 16:45:18.074: D/libc(24471): [NET] getaddrinfo-exit,err=8
08-02 16:45:18.074: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.074: D/libc(24471): [NET] ht 0x66772e776f6c66
08-02 16:45:18.074: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.074: D/libc(24471): [NET] android_getaddrinfo_proxy+
08-02 16:45:18.074: D/libc(24471): [NET]android_getaddrinfo_proxy+
08-02 16:45:18.074: D/libc(24471): [NET] check propname+
08-02 16:45:18.074: D/libc(24471): [NET] check propname-
08-02 16:45:18.084: D/libc(24471): [NET]android_getaddrinfo_proxy-,2
08-02 16:45:18.084: D/libc(24471): [NET] android_getaddrinfo_proxy-
08-02 16:45:18.084: D/libc(24471): [NET]_files_getaddrinfo+
08-02 16:45:18.084: D/libc(24471): [NET]_files_getaddrinfo-,1
08-02 16:45:18.084: D/libc(24471): [NET]_dns_getaddrinfo+
08-02 16:45:18.084: D/libc(24471): [NET]_dns_getaddrinfo-,3
08-02 16:45:18.084: D/libc(24471): [NET] getaddrinfo-exit,err=7
08-02 16:45:18.084: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.084: D/libc(24471): [NET] ht 0x66772e776f6c66
08-02 16:45:18.084: D/libc(24471): [NET] getaddrinfo-exit,err=8
08-02 16:45:18.084: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.084: D/libc(24471): [NET] ht 0x66772e776f6c66
08-02 16:45:18.084: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.084: D/libc(24471): [NET] android_getaddrinfo_proxy+
08-02 16:45:18.084: D/libc(24471): [NET]android_getaddrinfo_proxy+
08-02 16:45:18.084: D/libc(24471): [NET] check propname+
08-02 16:45:18.084: D/libc(24471): [NET] check propname-
08-02 16:45:18.084: D/libc(24471): [NET]android_getaddrinfo_proxy-,2
08-02 16:45:18.084: D/libc(24471): [NET] android_getaddrinfo_proxy-
08-02 16:45:18.084: D/libc(24471): [NET]_files_getaddrinfo+
08-02 16:45:18.084: D/libc(24471): [NET]_files_getaddrinfo-,1
08-02 16:45:18.084: D/libc(24471): [NET]_dns_getaddrinfo+
08-02 16:45:18.084: D/libc(24471): [NET]_dns_getaddrinfo-,3
08-02 16:45:18.084: D/libc(24471): [NET] getaddrinfo-exit,err=7
08-02 16:45:18.084: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.084: D/libc(24471): [NET] ht 0x66772e776f6c66
08-02 16:45:18.084: D/libc(24471): [NET] getaddrinfo-exit,err=8
08-02 16:45:18.084: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.084: D/libc(24471): [NET] ht 0x66772e776f6c66
08-02 16:45:18.084: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.084: D/libc(24471): [NET] android_getaddrinfo_proxy+
08-02 16:45:18.084: D/libc(24471): [NET]android_getaddrinfo_proxy+
08-02 16:45:18.084: D/libc(24471): [NET] check propname+
08-02 16:45:18.084: D/libc(24471): [NET] check propname-
08-02 16:45:18.094: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.094: D/libc(24471): [NET] ht 0x66772e776f6c66
08-02 16:45:18.094: D/libc(24471): [NET] getaddrinfo-exit,err=8
08-02 16:45:18.094: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.094: D/libc(24471): [NET] ht 0x66772e776f6c66
08-02 16:45:18.094: D/libc(24471): [NET] getaddrinfo  hn 14, servname NULL, ai_family 0+
08-02 16:45:18.094: D/libc(24471): [NET] android_getaddrinfo_proxy+
08-02 16:45:18.094: D/libc(24471): [NET]android_getaddrinfo_proxy+
08-02 16:45:18.094: D/libc(24471): [NET] check propname+
08-02 16:45:18.094: D/libc(24471): [NET] check propname-
08-02 16:45:18.354: D/libc(24471): [NET]android_getaddrinfo_proxy-,1
08-02 16:45:18.354: D/libc(24471): [NET] getaddrinfo-exit 1
08-02 16:45:18.354: D/libc(24471): [NET]android_getaddrinfo_proxy-,1
08-02 16:45:18.354: D/libc(24471): [NET] getaddrinfo-exit 1
08-02 16:45:48.967: D/Process(24471): killProcess, pid=24471
08-02 16:45:48.967: D/Process(24471): dalvik.system.VMStack.getThreadStackTrace(Native Method)
08-02 16:45:48.967: D/Process(24471): java.lang.Thread.getStackTrace(Thread.java:599)
08-02 16:45:48.967: D/Process(24471): android.os.Process.killProcess(Process.java:1004)
08-02 16:45:48.967: D/Process(24471): com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:123)
08-02 16:45:48.967: D/Process(24471): java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
08-02 16:45:48.967: D/Process(24471): java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
08-02 16:45:48.967: D/Process(24471): dalvik.system.NativeStart.main(Native Method)

这对任何人都有意义吗?我认为这可能与使用 RemObjects SDK 有关...

编辑3:

我删除了最后一个意图过滤器,因为它似乎是多余的。仍然在连接更改上获得 3 个触发器,这实际上没有任何意义。2,一个用于wifi /移动断开连接,一个用于另一个连接,这是有道理的。他们也都说

intent.getAction(): android.net.conn.CONNECTIVITY_CHANGE

ni.getDetailedState().name(): CONNECTED.

奇怪的东西

4

1 回答 1

0

正如您所知道的,当特定意图被命中时,广播接收器会被调用,所以我认为每当连接性发生变化时,您定义的所有意图都会被传递,就像 wifi 网络连接时一样,那么将调用以下意图:

行动 android:name="android.net.wifi.supplicant.CONNECTION_CHANGE"

于 2013-08-02T14:27:30.400 回答