address changed
This commit is contained in:
parent
b565450820
commit
875ca899b1
1 changed files with 10 additions and 3 deletions
|
@ -1,9 +1,10 @@
|
|||
package net.osmand.plus.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.TrafficStats;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.StrictMode;
|
||||
import android.text.format.Formatter;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
@ -68,11 +69,11 @@ public class ServerActivity extends AppCompatActivity {
|
|||
private void initServer() {
|
||||
final int THREAD_ID = 10000;
|
||||
TrafficStats.setThreadStatsTag(THREAD_ID);
|
||||
OsmAndHttpServer.HOSTNAME = getDeviceAddress();
|
||||
try {
|
||||
server = new OsmAndHttpServer();
|
||||
initialized = true;
|
||||
updateTextView("Server started at: http://" + OsmAndHttpServer.HOSTNAME
|
||||
+ ":" + OsmAndHttpServer.PORT);
|
||||
updateTextView("Server started at: http://" + getDeviceAddress() + ":" + OsmAndHttpServer.PORT);
|
||||
} catch (IOException e) {
|
||||
Toast.makeText(this,
|
||||
e.getLocalizedMessage(),
|
||||
|
@ -81,6 +82,12 @@ public class ServerActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private String getDeviceAddress() {
|
||||
WifiManager wm = (WifiManager) this.getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
|
||||
return ip != null ? ip : "0.0.0.0";
|
||||
}
|
||||
|
||||
private void deInitServer() {
|
||||
server.closeAllConnections();
|
||||
server.stop();
|
||||
|
|
Loading…
Reference in a new issue