Skip to content

[network_info_plus] Use new Android APIs - #1151

Merged
vbuberen merged 7 commits into
fluttercommunity:mainfrom
vbuberen:update/network_info_android_apis
Oct 4, 2022
Merged

vbuberen merged 7 commits into
fluttercommunity:mainfrom
vbuberen:update/network_info_android_apis

Conversation

@vbuberen

@vbuberen vbuberen commented Oct 3, 2022

Copy link
Copy Markdown
Collaborator

Description

While working on #1090 saw that plugin uses some deprecated APIs.
Namely, there were usages of:

I modified the code, so on devices with Android 12 (S) and newer plugin uses new recommended way of getting the same information. Now plugin relies on ConnectivityManager.getLinkProperties() and ConnectivityManager.getNetworkCapabilities() for such devices.
Both functions mention that they require Manifest.permission.ACCESS_NETWORK_STATE, but during testing on emulators code worked fine for me even without this permission being added into AndroidManifest. Nevertheless, add info about this permission to docs and README, since don't trust emulator much.

Additionally did a minor update to example app to show info in more pretty form:

Before:
Screenshot 2022-10-03 at 10 25 00

After:
Screenshot 2022-10-03 at 11 25 17

Related Issues

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated the version in pubspec.yaml and CHANGELOG.md.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val linkAddresses = connectivityManager?.getLinkProperties(connectivityManager.activeNetwork)?.linkAddresses

val ipV4Address = linkAddresses?.firstOrNull { linkAddress ->

@vbuberen vbuberen Oct 3, 2022 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filtering is added because API returns multiple addresses and only one of them is ipV4 that we need:
Screenshot 2022-10-02 at 22 50 50


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it, so it is easy to open Settings of example app and grant permission without introducing any dependency to handle permission in this app.

Comment thread docs/network_info_plus/usage.mdx
@miquelbeltran miquelbeltran added Hacktoberfest Issues taking part in Hacktoberfest hacktoberfest-accepted labels Oct 4, 2022
@vbuberen
vbuberen merged commit f750ae9 into fluttercommunity:main Oct 4, 2022
@miquelbeltran

Copy link
Copy Markdown
Member

2.3.0 published

@vbuberen
vbuberen deleted the update/network_info_android_apis branch October 4, 2022 09:07
@kostadin24

kostadin24 commented Oct 9, 2022 •

Copy link
Copy Markdown

I have Android 13 (Pixel 5).
Just updated my app to use 2.3.1
No more SSID. Location permission is granted, location service is ON, ACCESS_NETWORK_STATE is in manifest.
Also no BSSID.
It was OK with plugin version 2.2.0

Just tried with Android 9 and SSID is OK.

Example in plugin project also shows me SSID: null

@DaYang816

Copy link
Copy Markdown

Why is wifi name still null

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jan 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants