-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'android_network_address' of https://github.com/DDRBoxma…
- Loading branch information
Showing
5 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.musicpd; | ||
|
||
import android.content.Context; | ||
import android.net.ConnectivityManager; | ||
import android.net.LinkAddress; | ||
import android.net.LinkProperties; | ||
|
||
import java.net.Inet4Address; | ||
import java.net.InetAddress; | ||
import java.util.List; | ||
|
||
public class NetworkUtil { | ||
|
||
public static String getDeviceIPV4Address(Context context) { | ||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
LinkProperties linkProperties = connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork()); | ||
if (linkProperties != null) { | ||
List<LinkAddress> linkAddresses = linkProperties.getLinkAddresses(); | ||
for (LinkAddress address : linkAddresses) { | ||
if (!address.getAddress().isLinkLocalAddress() && !address.getAddress().isLoopbackAddress()) { | ||
InetAddress address1 = address.getAddress(); | ||
if (address1 instanceof Inet4Address) { | ||
return address1.getHostAddress(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M1,9l2,2c4.97,-4.97 13.03,-4.97 18,0l2,-2C16.93,2.93 7.08,2.93 1,9zM9,17l3,3 3,-3c-1.65,-1.66 -4.34,-1.66 -6,0zM5,13l2,2c2.76,-2.76 7.24,-2.76 10,0l2,-2C15.14,9.14 8.87,9.14 5,13z"/> | ||
</vector> |
This file contains 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 characters