Ionic 7 internet access does not work. But status.connected
(@capacitor/network) says true. I think android deny the connection.
package.json part:
{
"dependencies": {
"@angular/common": "^16.0.0",
"@capacitor/android": "5.0.5",
"@capacitor/network": "^5.0.6",
"@ionic/angular": "^7.1.0"
}
}
AndroidManifest.xml part:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:usesCleartextTraffic="true">
</application>
</manifest>
main.ts part:
import {ConnectionStatus, Network} from '@capacitor/network';
export const networkStatus: ConnectionStatus = {
connected: false,
connectionType: 'none'
};
/**
* ERROR: event does not fire
*/
Network.addListener('networkStatusChange', status => {
networkStatus.connected = status.connected;
networkStatus.connectionType = status.connectionType;
});
app.component.ts part:
import {Network} from '@capacitor/network';
import {networkStatus} from '../main';
export class AppComponent {
async refreshNetworkStatus() {
const status = await Network.getStatus();
this.netStat.connected = status.connected;
this.netStat.connectionType = status.connectionType;
}
}
The first problem is Network.addListener('networkStatusChange')
(main.ts) does not fire. In the app.component.ts the function refreshNetworkStatus()
works and show me status=true and type=wifi. So, it looks good. But I can't access anything on the network.
Why can't I access the Internet?
When installing the app, Android does not ask whether it can access the Internet. I think Android should ask because I say in the AndroidManifest.xml that I want.
Why doesn't Android ask for the right to access the Internet?
test devices
- Motorola Moto G22 - Android 12
- Fairphone 4 5G - Android 13
- Google Pixel 5 - Android 11
- Asus ZenFone 3 - Android 8
My mistake is somewhere else. With the above configuration, Internet access works in Android.