@capacitor-community/local-network
Check and request the Android 17+ (API 37) local network access permission
Android 17 (API 37) introduced the ACCESS_LOCAL_NETWORK runtime permission, and Android only enforces it against applications that target API 37 or later:
| Your application | Local network access |
|---|---|
| Targets API 37+ | Blocked by default. The permission must be requested at runtime. |
| Targets API 36 or lower | Granted implicitly. The permission is not enforced. |
The Capacitor 8 application template ships targetSdkVersion 36, so with the defaults the permission is not enforced and this plugin reports granted without showing a prompt. See Installation for how to target API 37.
This plugin was extracted from the Capacitor 9 core proposal (ionic-team/capacitor#8624) at the maintainers' request — see capacitor-community/proposals#244.
| Maintainer | GitHub | Social | Website |
|---|---|---|---|
| Fabio Martino | fabiomartino | — | — |
| Capacitor Community | capacitor-community | — | capacitorjs.com |
Maintenance Status: Actively Maintained
A working example can be found in the example-app directory.
checkPermissions()requestPermissions()addListener('permissionChange', ...)addListener(string, ...)removeAllListeners()getPluginVersion()- Interfaces
- Type Aliases
checkPermissions() => Promise<LocalNetworkPermissions>Checks the current state of the local-network permission.
Android 17+ (API 37) reports the real runtime permission state
(granted, denied or prompt).
On older Android versions, iOS and web the permission is not enforced
and is always reported as granted, so calling this method never
triggers a system prompt.
Returns: Promise<LocalNetworkPermissions>
Since: 8.0.0
requestPermissions() => Promise<LocalNetworkPermissions>Requests the local-network permission.
Android 17+ (API 37) shows the system permission prompt when the permission has not been decided yet, then resolves with the resulting state. A denied decision is reported as state, not as a rejection.
On older Android versions, iOS and web the permission is not enforced
and the call resolves immediately with granted.
Returns: Promise<LocalNetworkPermissions>
Since: 8.0.0
addListener(eventName: 'permissionChange', listenerFunc: (event: LocalNetworkPermissionChangeEvent) => void) => Promise<PluginListenerHandle>Listen for changes to the local-network permission state.
Emits when the permission state changes (e.g. after returning from system settings).
On platforms where the permission is not enforced, this will typically remain granted.
| Param | Type |
|---|---|
eventName |
'permissionChange' |
listenerFunc |
(event: LocalNetworkPermissionChangeEvent) => void |
Returns: Promise<PluginListenerHandle>
Since: 8.0.0
addListener(eventName: string, listenerFunc: (...args: unknown[]) => void) => Promise<PluginListenerHandle>Registers a listener for plugin events using a generic event name.
Prefer the typed permissionChange overload for full payload type safety.
| Param | Type |
|---|---|
eventName |
string |
listenerFunc |
(...args: unknown[]) => void |
Returns: Promise<PluginListenerHandle>
Since: 8.0.0
removeAllListeners() => Promise<void>Removes all registered listeners for this plugin.
Since: 8.0.0
getPluginVersion() => Promise<PluginVersionResult>Returns the native plugin version.
The returned version corresponds to the native implementation bundled with the application.
Returns: Promise<PluginVersionResult>
Since: 8.0.0
Result of the LocalNetwork permission flow.
The property is declared explicitly (not via an index signature) so that
consumers can use dot access (result.localNetwork) even with the
noPropertyAccessFromIndexSignature compiler option enabled.
| Prop | Type | Description |
|---|---|---|
localNetwork |
PermissionState |
State of the local-network (ACCESS_LOCAL_NETWORK) permission. On Android 17+ (API 37) this reflects the runtime permission state. On older Android versions, iOS and web the permission does not gate local-network access and is always reported as granted. |
| Prop | Type |
|---|---|
remove |
() => Promise<void> |
Event emitted when the local-network permission state changes. Useful when the user returns from system settings after changing the permission.
| Prop | Type | Description |
|---|---|---|
localNetwork |
PermissionState |
Current state of the local-network permission |
Result object returned by the getPluginVersion() method.
| Prop | Type | Description |
|---|---|---|
version |
string |
The native version string of the plugin. |
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
