How to get IP address of cellular network when device is connected to WiFi in Android

Asus gates

Is there a way through which I can get IP address of both WiFi and cellular network in Android simultaneously.I tried using many examples but was able to get Address of only WiFi network and not cellular network.I have enabled both WiFi and cellular network and device is having Internet access through WiFi.

Here is the code which I am using to get the IP address:

    String ipAddress = null;
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    ipAddress = inetAddress.getHostAddress().toString();
                    Log.i("Here is the Address",ipAddress);
                }
            }
        }
    } catch (SocketException ex) {

    }

Is it possible to get IP address of cellular network when device is connected to WiFi.If yes how is that feasible.

Aenadon

Whenever you enable WiFi on your device AND have an active connection to a WiFi network, your mobile data is temporarily disabled, no matter if you have enabled it manually or not. The setting "Mobile data on/off" is only taken into consideration if you have no active WiFi connection.

Some custom ROMs have an option to keep the mobile connection alive when you connect to a WiFi (so in case you lose your WiFi connection, it switches to mobile faster), but still, the WiFi connection is used.

Conclusion: You cannot get both IP addresses as you cannot have both WiFi and mobile network on (and if you can, you only use WiFi actively)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Get IP Address used to connect to Firebase from Android device

分類Dev

How to get the Android device's primary e-mail address

分類Dev

find host ip address when guest machine is connected to host

分類Dev

How to block an IP address from a network share

分類Dev

Recover a net device, I don't know IP-address, how to get arp?

分類Dev

What IP address should I use to connect MySQL with Android Device

分類Dev

Get connected HDMI device's HDMI version in android app

分類Dev

How to get all MAC addresses connected to WiFi with node.js?

分類Dev

How to know a mac address for a Node knowing its IP on local network?

分類Dev

Get IP of wifi gateway?

分類Dev

Get Ip address of ethernet if not present then get it of WIFI adapter using Batch script

分類Dev

How google map fetching address even android device is offline

分類Dev

Genymotion: The virtual device got no IP address?

分類Dev

IP address/ OS version and device key

分類Dev

How to get device id for Audience Network of Facebook in Flutter?

分類Dev

how can i get clients ip address on UDP server in golang?

分類Dev

How to get client IP address in Laravel 5+

分類Dev

how to get container host machine ip address and container name in EKS

分類Dev

How to get IP address from controller's hosts file in Ansible?

分類Dev

How to get k8s master ip address?

分類Dev

How to resolve a remote computer name to get it IP address in java

分類Dev

How to get the ip address of a computer from its hostname?

分類Dev

Local network device changing other IP addresses

分類Dev

Android - How to Unblock Your IP address from Firebase?

分類Dev

Gateway iP address after increasing network to /22

分類Dev

Script to set IP address connected to an interface to a shell variable

分類Dev

Virtualbox: get host IP address

分類Dev

How can I assign a static IP to just one device on my home network?

分類Dev

How does an AWS IoT device show as "connected"

Related 関連記事

  1. 1

    Get IP Address used to connect to Firebase from Android device

  2. 2

    How to get the Android device's primary e-mail address

  3. 3

    find host ip address when guest machine is connected to host

  4. 4

    How to block an IP address from a network share

  5. 5

    Recover a net device, I don't know IP-address, how to get arp?

  6. 6

    What IP address should I use to connect MySQL with Android Device

  7. 7

    Get connected HDMI device's HDMI version in android app

  8. 8

    How to get all MAC addresses connected to WiFi with node.js?

  9. 9

    How to know a mac address for a Node knowing its IP on local network?

  10. 10

    Get IP of wifi gateway?

  11. 11

    Get Ip address of ethernet if not present then get it of WIFI adapter using Batch script

  12. 12

    How google map fetching address even android device is offline

  13. 13

    Genymotion: The virtual device got no IP address?

  14. 14

    IP address/ OS version and device key

  15. 15

    How to get device id for Audience Network of Facebook in Flutter?

  16. 16

    how can i get clients ip address on UDP server in golang?

  17. 17

    How to get client IP address in Laravel 5+

  18. 18

    how to get container host machine ip address and container name in EKS

  19. 19

    How to get IP address from controller's hosts file in Ansible?

  20. 20

    How to get k8s master ip address?

  21. 21

    How to resolve a remote computer name to get it IP address in java

  22. 22

    How to get the ip address of a computer from its hostname?

  23. 23

    Local network device changing other IP addresses

  24. 24

    Android - How to Unblock Your IP address from Firebase?

  25. 25

    Gateway iP address after increasing network to /22

  26. 26

    Script to set IP address connected to an interface to a shell variable

  27. 27

    Virtualbox: get host IP address

  28. 28

    How can I assign a static IP to just one device on my home network?

  29. 29

    How does an AWS IoT device show as "connected"

ホットタグ

アーカイブ