Created
September 30, 2014 16:30
-
-
Save dominicbartl/3dd1f036ddea41f3c39f to your computer and use it in GitHub Desktop.
Revisions
-
dominicbartl created this gist
Sep 30, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ private static final String HOST_EMULATOR = "10.0.2.2"; private static final String HOST_PRODUCTION = "example.com"; public static String getHost() { if (BuildConfig.DEBUG) { return (Build.PRODUCT).contains("sdk") ? HOST_EMULATOR : BuildConfig.LOCAL_IP; } return HOST_PRODUCTION; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ ... android { defaultConfig { minSdkVersion 14 targetSdkVersion 19 buildConfigField "String", "LOCAL_IP", '\"' + getLocalIp("eth0") + '\"' } } // Get the ip address by interface name def getLocalIp(String interfaceName) { NetworkInterface iface = NetworkInterface.getByName(interfaceName); for (InterfaceAddress address : iface.getInterfaceAddresses()) { String ip = address.getAddress().getHostAddress() if (ip.length() <= 15) { return ip; } } }