我有一个在我的清单中注册的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:
我删除了最后一个intent-filter,因为它似乎是多余的。仍然在连接更改上获得3个触发器,这实际上没有意义。 2,一个用于wifi /移动断开,一个用于另一个连接,这是有道理的。他们都说
intent.getAction(): android.net.conn.CONNECTIVITY_CHANGE
和
ni.getDetailedState().name(): CONNECTED.
奇怪的东西
答案 0 :(得分:0)
正如您所知,当特定意图被击中时,广播接收器被调用,所以我认为每当连接改变您定义的所有意图被传递时,如果连接了wifi网络,则将调用以下意图:
动作android:name =&#34; android.net.wifi.supplicant.CONNECTION_CHANGE&#34;