|
| 1 | +<!DOCTYPE html> |
| 2 | +<!-- |
| 3 | + | Generated by Apache Maven Doxia Site Renderer 1.9.2 from src/site/markdown/android.md at 2022-07-04 |
| 4 | + | Rendered using Apache Maven Fluido Skin 1.9 |
| 5 | +--> |
| 6 | +<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> |
| 7 | + <head> |
| 8 | + <meta charset="UTF-8" /> |
| 9 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 10 | + <meta name="generator" content="Apache Maven Doxia Site Renderer 1.9.2" /> |
| 11 | + <title>socket.io-client – Android</title> |
| 12 | + <link rel="stylesheet" href="./css/apache-maven-fluido-1.9.min.css" /> |
| 13 | + <link rel="stylesheet" href="./css/site.css" /> |
| 14 | + <link rel="stylesheet" href="./css/print.css" media="print" /> |
| 15 | + <script src="./js/apache-maven-fluido-1.9.min.js"></script> |
| 16 | + </head> |
| 17 | + <body class="topBarDisabled"> |
| 18 | + <a href="https://github.com/socketio/socket.io-client-java"> |
| 19 | + <img style="position: absolute; top: 0; right: 0; border: 0; z-index: 10000;" |
| 20 | + src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" |
| 21 | + alt="Fork me on GitHub"> |
| 22 | + </a> |
| 23 | + <div class="container-fluid"> |
| 24 | + <header> |
| 25 | + <div id="banner"> |
| 26 | + <div class="pull-left"><div id="bannerLeft"><h2>Socket.IO Java client</h2> |
| 27 | +</div> |
| 28 | +</div> |
| 29 | + <div class="pull-right"></div> |
| 30 | + <div class="clear"><hr/></div> |
| 31 | + </div> |
| 32 | + |
| 33 | + <div id="breadcrumbs"> |
| 34 | + <ul class="breadcrumb"> |
| 35 | + <li id="publishDate">Last Published: 2022-07-04<span class="divider">|</span> |
| 36 | +</li> |
| 37 | + <li id="projectVersion">Version: 2.0.2-SNAPSHOT</li> |
| 38 | + </ul> |
| 39 | + </div> |
| 40 | + </header> |
| 41 | + <div class="row-fluid"> |
| 42 | + <header id="leftColumn" class="span2"> |
| 43 | + <nav class="well sidebar-nav"> |
| 44 | + <ul class="nav nav-list"> |
| 45 | + <li class="nav-header">Overview</li> |
| 46 | + <li><a href="installation.html" title="Installation"><span class="none"></span>Installation</a></li> |
| 47 | + <li><a href="initialization.html" title="Initialization"><span class="none"></span>Initialization</a></li> |
| 48 | + <li><a href="emitting_events.html" title="Emitting events"><span class="none"></span>Emitting events</a></li> |
| 49 | + <li><a href="listening_to_events.html" title="Listening to events"><span class="none"></span>Listening to events</a></li> |
| 50 | + <li><a href="socket_instance.html" title="The Socket instance"><span class="none"></span>The Socket instance</a></li> |
| 51 | + <li><a href="migrating_from_1_x.html" title="Migrating from 1.x"><span class="none"></span>Migrating from 1.x</a></li> |
| 52 | + <li><a href="faq.html" title="FAQ"><span class="none"></span>FAQ</a></li> |
| 53 | + <li class="active"><a href="#"><span class="none"></span>Android</a></li> |
| 54 | + <li class="nav-header">Miscellaneous</li> |
| 55 | + <li><a href="changelog.html" title="Changelog"><span class="none"></span>Changelog</a></li> |
| 56 | + <li><a href="apidocs/index.html" title="Javadoc"><span class="none"></span>Javadoc</a></li> |
| 57 | + <li class="nav-header">Project Documentation</li> |
| 58 | + <li><a href="project-info.html" title="Project Information"><span class="icon-chevron-right"></span>Project Information</a></li> |
| 59 | + </ul> |
| 60 | + </nav> |
| 61 | + <div class="well sidebar-nav"> |
| 62 | + <hr /> |
| 63 | + <div id="poweredBy"> |
| 64 | + <div class="clear"></div> |
| 65 | + <div class="clear"></div> |
| 66 | + <div class="clear"></div> |
| 67 | +<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"><img class="builtBy" alt="Built by Maven" src="./images/logos/maven-feather.png" /></a> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + </header> |
| 71 | + <main id="bodyColumn" class="span10" > |
| 72 | +<h1>Android</h1> |
| 73 | +<ul> |
| 74 | +<li><a href="#How_to_keep_a_Socket.IO_client_running_in_the_background.3F">How to keep a Socket.IO client running in the background?</a></li> |
| 75 | +<li><a href="#How_to_reach_an_HTTP_server.3F">How to reach an HTTP server?</a></li></ul> |
| 76 | +<section> |
| 77 | +<h2><a name="How_to_keep_a_Socket.IO_client_running_in_the_background.3F"></a>How to keep a Socket.IO client running in the background?</h2> |
| 78 | +<p>Long story short, you probably shouldn’t. The Socket.IO client is not meant to be used in a <a class="externalLink" href="https://developer.android.com/guide/components/services?hl=en">background service</a>, as it will keep an open TCP connection to the server and quickly drain the battery of your users.</p> |
| 79 | +<p>It is totally usable in the foreground though.</p> |
| 80 | +<p>See also: <a class="externalLink" href="https://developer.android.com/training/connectivity">https://developer.android.com/training/connectivity</a></p></section><section> |
| 81 | +<h2><a name="How_to_reach_an_HTTP_server.3F"></a>How to reach an HTTP server?</h2> |
| 82 | +<p>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 <code>http://192.168.0.10</code>):</p> |
| 83 | +<ul> |
| 84 | + |
| 85 | +<li>either for all domains:</li> |
| 86 | +</ul> |
| 87 | +<p><code>app/src/main/AndroidManifest.xml</code></p> |
| 88 | + |
| 89 | +<div class="source"> |
| 90 | +<div class="source"><pre class="prettyprint"><?xml version="1.0" encoding="utf-8"?> |
| 91 | +<manifest> |
| 92 | + <uses-permission android:name="android.permission.INTERNET" /> |
| 93 | + |
| 94 | + <application android:usesCleartextTraffic="true"> |
| 95 | + ... |
| 96 | + </application> |
| 97 | +</manifest> |
| 98 | +</pre></div></div> |
| 99 | + |
| 100 | +<ul> |
| 101 | + |
| 102 | +<li>or for a restricted list of domains:</li> |
| 103 | +</ul> |
| 104 | +<p><code>app/src/main/AndroidManifest.xml</code></p> |
| 105 | + |
| 106 | +<div class="source"> |
| 107 | +<div class="source"><pre class="prettyprint"><?xml version="1.0" encoding="utf-8"?> |
| 108 | +<manifest> |
| 109 | + <uses-permission android:name="android.permission.INTERNET" /> |
| 110 | + |
| 111 | + <application android:networkSecurityConfig="@xml/network_security_config"> |
| 112 | + ... |
| 113 | + </application> |
| 114 | +</manifest> |
| 115 | +</pre></div></div> |
| 116 | + |
| 117 | +<p><code>app/src/main/res/xml/network_security_config.xml</code></p> |
| 118 | + |
| 119 | +<div class="source"> |
| 120 | +<div class="source"><pre class="prettyprint"><?xml version="1.0" encoding="utf-8"?> |
| 121 | +<network-security-config> |
| 122 | + <domain-config cleartextTrafficPermitted="true"> |
| 123 | + <domain includeSubdomains="true">localhost</domain> |
| 124 | + <domain includeSubdomains="true">192.168.0.10</domain> |
| 125 | + </domain-config> |
| 126 | +</network-security-config> |
| 127 | +</pre></div></div> |
| 128 | + |
| 129 | +<p>Reference: <a class="externalLink" href="https://developer.android.com/training/articles/security-config">https://developer.android.com/training/articles/security-config</a></p></section> |
| 130 | + </main> |
| 131 | + </div> |
| 132 | + </div> |
| 133 | + <hr/> |
| 134 | + <footer> |
| 135 | + <div class="container-fluid"> |
| 136 | + <div class="row-fluid"> |
| 137 | + <p>© 2022 |
| 138 | +</p> |
| 139 | + </div> |
| 140 | + </div> |
| 141 | + </footer> |
| 142 | + </body> |
| 143 | +</html> |
0 commit comments