Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

bug(network): Android networkStatusChange re-queries the active network inside callbacks and fires on every capability change

オープン
#2,621 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@kcjonson がすでに取り組んでいます。

2026年10月22日 から。

  • #2622 @kcjonson による — オープン

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
android, java
領域
mobile, networking

調査の方向性

Start with network/android/src/main/java/com/getcapacitorjs/plugins/network/Network.java and NetworkPlugin.java, especially the callback, status calculation, and lifecycle registration methods linked in the issue. Review the open linked pull request #2622 and compare its changes with the expected behavior. Done means callback arguments provide status, duplicate events are suppressed, monitoring starts on load, and registration is safe across lifecycle calls.

索引モデルが issue の本文から書いたものです。

説明

platform: android

Bug Report

Plugin(s)

@capacitor/network 8.0.1 (same code on main at 87c0bb8 and in 9.0.0-alpha.2)

Capacitor Version
@capacitor/core: 8.5.3
@capacitor/android: 8.5.3
@capacitor/network: 8.0.1
compileSdk 36, minSdk 24
Platform(s)

Android

Current Behavior
  1. The network callback ignores its arguments and re-queries the active network. onCapabilitiesChanged drops the NetworkCapabilities it receives (Network.java:29-32); NetworkPlugin then calls getNetworkStatus() (NetworkPlugin.java:84-86), which calls getActiveNetwork() twice and getNetworkCapabilities() (Network.java:77-78). The ConnectivityManager.NetworkCallback reference says not to call synchronous ConnectivityManager methods from inside callbacks, because the result can be out of date relative to the callback; the arguments passed in are the source of truth. onLost also emits none for any lost network without checking it was the current default (Network.java:22-26, NetworkPlugin.java:25-29).

  2. Every capability change emits an event, even when nothing reported changed. There is no comparison with the last emitted status (NetworkPlugin.java:84-86). onCapabilitiesChanged fires for signal strength and link bandwidth updates, so listeners get repeated networkStatusChange events with an identical { connected, connectionType }. Registering the callback on each resume also delivers an immediate callback, so every resume emits too. This was acknowledged as a bug in ionic-team/capacitor#1492 (labeled type: bug, diagnosed as the onResume registration) and reported again in #1014 and #2138; all were closed in backlog cleanup without a fix.

  3. No events before the first resume. load() only sets the listener (NetworkPlugin.java:22-35); startMonitoring() is only called from handleOnResume (NetworkPlugin.java:59).

  4. Unguarded register/unregister. startMonitoring/stopMonitoring call registerDefaultNetworkCallback/unregisterNetworkCallback with no registered-state check (Network.java:114-123). Android throws IllegalArgumentException when unregistering a callback that isn't registered or registering one twice, so a pause without a preceding resume, or a repeated pause, can crash. Not reproduced; possibly related to #2107.

Expected Behavior
  • Status in callbacks comes from the callback's own Network/NetworkCapabilities.
  • networkStatusChange fires only when connected or connectionType actually changes.
  • Monitoring starts when the plugin loads.
  • Register/unregister can't throw on lifecycle ordering.
Code Reproduction

No sample app needed beyond the plugin's own example:

import { Network } from '@capacitor/network';
Network.addListener('networkStatusChange', s => console.log('event', Date.now(), JSON.stringify(s)));
  1. Run on a device connected to Wi-Fi.
  2. Walk away from the router and back (or move between rooms) so the signal level changes, without disconnecting.
  3. Logcat shows repeated networkStatusChange events, each with {"connected":true,"connectionType":"wifi"}.
  4. Background and foreground the app (open the notification shade, a permission dialog, or the app switcher): one more identical event per resume.
Other Technical Details

A PR follows. It keeps connected = VALIDATED && INTERNET and keeps getStatus() querying the active network as today. It doesn't change the public API.

Related open items, not duplicated by the PR: #2563 / #2606 (ANR from ConnectivityManager calls on the main thread in handleOnResume), #2564 (captive portal / limited state), #2555 (metered / constrained flags).

Additional Context

Prior reports: ionic-team/capacitor#1492, #1014, #2138, #2107.

主要言語
Java
スター
687
フォーク
691
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ionic-team/capacitor-plugins のほかの issue

ionic-team/capacitor-plugins の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。