Skip to content

Commit 18b2fca

Browse files
docs: init Android documentation
Related: - #606 - #435
1 parent 0cbf01e commit 18b2fca

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/site/markdown/android.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Android
2+
3+
<!-- MACRO{toc} -->
4+
5+
## How to keep a Socket.IO client running in the background?
6+
7+
Long story short, you probably shouldn't. The Socket.IO client is not meant to be used in a [background service](https://developer.android.com/guide/components/services?hl=en), as it will keep an open TCP connection to the server and quickly drain the battery of your users.
8+
9+
It is totally usable in the foreground though.
10+
11+
See also: https://developer.android.com/training/connectivity
12+
13+
## How to reach an HTTP server?
14+
15+
Starting with Android 9 (API level 28) you need to explicitly allow cleartext traffic to be able to reach an HTTP server (e.g. a local server at `http://192.168.0.10`):
16+
17+
- either for all domains:
18+
19+
`app/src/main/AndroidManifest.xml`
20+
21+
```xml
22+
<?xml version="1.0" encoding="utf-8"?>
23+
<manifest>
24+
<uses-permission android:name="android.permission.INTERNET" />
25+
26+
<application android:usesCleartextTraffic="true">
27+
...
28+
</application>
29+
</manifest>
30+
```
31+
32+
- or for a restricted list of domains:
33+
34+
`app/src/main/AndroidManifest.xml`
35+
36+
```xml
37+
<?xml version="1.0" encoding="utf-8"?>
38+
<manifest>
39+
<uses-permission android:name="android.permission.INTERNET" />
40+
41+
<application android:networkSecurityConfig="@xml/network_security_config">
42+
...
43+
</application>
44+
</manifest>
45+
```
46+
47+
`app/src/main/res/xml/network_security_config.xml`
48+
49+
```xml
50+
<?xml version="1.0" encoding="utf-8"?>
51+
<network-security-config>
52+
<domain-config cleartextTrafficPermitted="true">
53+
<domain includeSubdomains="true">localhost</domain>
54+
<domain includeSubdomains="true">192.168.0.10</domain>
55+
</domain-config>
56+
</network-security-config>
57+
```
58+
59+
Reference: https://developer.android.com/training/articles/security-config

src/site/site.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<item name="The Socket instance" href="./socket_instance.html"/>
3232
<item name="Migrating from 1.x" href="./migrating_from_1_x.html"/>
3333
<item name="FAQ" href="./faq.html"/>
34+
<item name="Android" href="./android.html"/>
3435
</menu>
3536

3637
<menu name="Miscellaneous">

0 commit comments

Comments
 (0)