Repository navigation
Will Capacitor 9 support the new ACCESS_LOCAL_NETWORK permission in Android 17 (SDK 37)? #8610
|
Android 17 (SDK37) introduces a new network permission for accessing devices on the local network, "android.permission.ACCESS_LOCAL_NETWORK". Permission to access local network devices used to be granted automatically with "android.permission.INTERNET", but starting with SDK 37 the permission must be granted deliberately. See https://developer.android.com/privacy-and-security/local-network-permission. As a test I set targetSDK=37 and sure enough, connections to IoT devices on my LAN silently fail. :( |
Replies: 2 comments 2 replies
|
You don't need to wait for Capacitor for this. From the official docs:
1. Declare it in <uses-permission android:name="android.permission.ACCESS_LOCAL_NETWORK" />2. Request it at runtime. The simplest way in a Capacitor app is from class MainActivity : BridgeActivity() {
private val requestLocalNetwork =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
// tell your web layer, e.g. via a plugin event, if you need to
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT >= 37 &&
ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_LOCAL_NETWORK)
!= PackageManager.PERMISSION_GRANTED
) {
requestLocalNetwork.launch(Manifest.permission.ACCESS_LOCAL_NETWORK)
}
}
}If you want to ask for the permission in context (for example when the user opens the "add device" screen) rather than at launch, wrap it in a small local plugin. Declare it with Alternative that needs no permission: if you only have to discover and connect to specific devices over mDNS/NSD, Android 17 adds a system picker ( So nothing is blocking you on the Capacitor side. Whether Capacitor 9 (currently in alpha) will add a built-in helper is up to the maintainers, but the manifest entry plus a runtime request is enough to make targetSdk 37 work. |
|
This has been reported as a bug in issue #8613 and a PR proposed #8624, so work is progressing nicely on this. I'll close this discussion, so comments and feedback will happen in those threads. Thanks to @ahmetoguzer and @fabiomartino for making the effort to address this issue. |
You don't need to wait for Capacitor for this.
ACCESS_LOCAL_NETWORKis a regular Android runtime permission, so your app can declare and request it today.From the official docs:
INTERNETstill grants it implicitly, which is why everything worked before you bumped the target.NEARBY_DEVICESgroup. Declaring it in the manifest isn't enough; the user has to grant it.EPERM. That's the "silent" failure you're seeing. Internet traffic isn't affected.1. Declare it in
a…