android: Add a text field to display the devices network address

This commit is contained in:
Colin Edwards 2023-12-21 00:04:17 -06:00
parent 2c851498cc
commit c4c1044427
5 changed files with 70 additions and 8 deletions

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.musicpd"
android:installLocation="auto"
android:versionCode="73"
android:versionName="0.23.15">
@ -12,6 +11,7 @@
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />

View File

@ -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;
}
}

View File

@ -213,6 +213,10 @@ public class Settings extends Activity {
if (Preferences.getBoolean(this, Preferences.KEY_PAUSE_ON_HEADPHONES_DISCONNECT, false))
checkbox.setChecked(true);
TextView networkAddressTextView = (TextView) findViewById(R.id.networkAddress);
String deviceIPV4Address = NetworkUtil.getDeviceIPV4Address(this);
networkAddressTextView.setText(deviceIPV4Address);
super.onCreate(savedInstanceState);
}

View File

@ -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>

View File

@ -2,14 +2,36 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="@drawable/baseline_wifi_24"
android:layout_margin="4dp"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/networkAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="24sp"
android:gravity="center"
android:padding="4dp"
android:textSize="24sp" />
</LinearLayout>
<ToggleButton
android:id="@+id/run"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textOn="@string/toggle_button_run_on"
android:textOff="@string/toggle_button_run_off" />
android:textOff="@string/toggle_button_run_off"
android:textOn="@string/toggle_button_run_on" />
<CheckBox
android:id="@+id/run_on_boot"
@ -35,9 +57,9 @@
android:layout_height="wrap_content" />
<ListView
android:id="@+id/log_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip" />
android:id="@+id/log_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip" />
</LinearLayout>