|
|
@ -6,14 +6,20 @@ import android.content.ContentValues;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
|
|
|
|
import android.net.LinkProperties;
|
|
|
|
|
|
|
|
import android.net.Network;
|
|
|
|
|
|
|
|
import android.net.NetworkCapabilities;
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.net.Uri;
|
|
|
|
|
|
|
|
import android.net.wifi.WifiManager;
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
import android.text.format.Formatter;
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.Inet4Address;
|
|
|
|
import java.net.Inet4Address;
|
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.NetworkInterface;
|
|
|
|
import java.net.NetworkInterface;
|
|
|
|
|
|
|
|
import java.net.SocketException;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.util.Enumeration;
|
|
|
|
import java.util.Enumeration;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
@ -55,7 +61,7 @@ public class NetworkUtils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String getMobileNetworkIp(Context context) {
|
|
|
|
public static String getMobileNetworkIp(Context context) {
|
|
|
|
ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
@SuppressLint("MissingPermission") NetworkInfo[] networkInfos = connectivityManager.getAllNetworkInfo();
|
|
|
|
@SuppressLint("MissingPermission") NetworkInfo[] networkInfos = connectivityManager.getAllNetworkInfo();
|
|
|
|
|
|
|
|
|
|
|
|
if (networkInfos == null || networkInfos.length == 0) {
|
|
|
|
if (networkInfos == null || networkInfos.length == 0) {
|
|
|
@ -89,6 +95,29 @@ public class NetworkUtils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String getMobileIPAddress() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
|
|
|
|
|
|
|
while (interfaces.hasMoreElements()) {
|
|
|
|
|
|
|
|
NetworkInterface networkInterface = interfaces.nextElement();
|
|
|
|
|
|
|
|
if (networkInterface.isUp() && !networkInterface.isLoopback()) {
|
|
|
|
|
|
|
|
if (networkInterface.getName() != null && !networkInterface.getName().contains("ap")) {
|
|
|
|
|
|
|
|
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
|
|
|
|
|
|
|
|
while (addresses.hasMoreElements()) {
|
|
|
|
|
|
|
|
InetAddress address = addresses.nextElement();
|
|
|
|
|
|
|
|
if (!address.isLoopbackAddress() && address.getAddress().length == 4) { // IPv4
|
|
|
|
|
|
|
|
return address.getHostAddress();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SocketException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static int addAPN(Context context, String name, String desc, String numeric, String user, String pwd) {
|
|
|
|
public static int addAPN(Context context, String name, String desc, String numeric, String user, String pwd) {
|
|
|
|
int id = -1;
|
|
|
|
int id = -1;
|
|
|
|
String NUMERIC = getSIMInfo(context);
|
|
|
|
String NUMERIC = getSIMInfo(context);
|
|
|
|