Ketai library, KetaiNet.getIP(); Error

Hi. ketai library related.

import ketai.net.wifidirect.;
import ketai.net.
;
import ketai.ui.*;

KetaiNet.getIP();

KetaiNet.getIP (); The function does not work properly.
It does not get the correct IP address value.

Android version 8.0: works fine
Android version 9.0: Strange IP address

Is there any way to solve it?

@GWAK ===
can you put the code you are using?
can you put the console error message (if it exists)?
what do you mean by Android version? - Is it compiling with or running on a device with 8 or 9?
how is your Manifest?

@akenaton

Are you an angel?
Thank you for your kind answers.

import android.os.Bundle;

import ketai.net.;
import ketai.ui.
;
import oscP5.;
import netP5.
;
void setup()
{
fullScreen();
orientation(PORTRAIT);
println(KetaiNet.getIP());
}

Please take a look at the picture of the hardware.
The Wi-Fi module constitutes the network and the smart phone is connected.
(picture)The current IP address is the IP address given on the actual network.

(source code result : )
Smartphone Android version 6.0 ~ 8.0: 192.168.4.2
Smartphone Android version 9.0: 192.0.0.5

The cause of the phenomenon seems to be the phenomenon after updating the Android version.

I would like to know IP address(smartphone) at the moment. Is there a way?

What value do you get? “0.0.0.0”

How are you setting up to use ver 9? Is that through your manifest?
I confirm it works in ver 8 (Api 26 (?) ) and I enabled internet and access_network_state. I might only need one of them as i did not check the docs.

Kf

1 Like

@kfrajer

I use android version 9.0
Permissions :

  1. ACCESS_NEXWORK_STATE
  2. ACCESS_WIFI_STATE
  3. INTERNET

@GWAK ===
so you are running this code on a device with android 9 installed. Now, what about your Manifest?Is uour SDK updated to this API ?

1 Like

@akenaton, @kfrajer

Dear akenaton, kfrajer

Example1)
target SDK : API9 / Smartphone Android 9.0 :: Strange value ip address

Example2)
target SDK : API9 / Smartphone Android 8.0 :: Correct ip address

Example3)
target SDK : API8.1 / Smartphone Android 9.0 :: Strange value ip address

Example4)
target SDK : API7.0 / Smartphone Android 9.0 :: Strange value ip address

in conclusion,

I think it’s a fatal error on Android version 9.0(Smart Phone).
Do not you guys do that, too?

I solved it.

Source code

      if (!inetAddress.isLoopbackAddress()
          && thing == "0.0.0.0"
          && inetAddress.getHostAddress().matches(
              "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b")) {
        thing = inetAddress.getHostAddress();
      }

Corrected source code

      if (!inetAddress.isLoopbackAddress()
          // && thing == "0.0.0.0"
          && inetAddress.getHostAddress().matches(
              "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b")) {
        thing = inetAddress.getHostAddress();
      }

It seems to be a bug since it was version 9.0 of Android.
Anyhow, commenting like that is done.

thank you.

tt

Based on this https://stackoverflow.com/a/10199498/7229333

There must be a reason for that comparison there that you are commenting out. With your suggested change, I would recommend the next additional change so from:

thing = inetAddress.getHostAddress();

to

return inetAddress.getHostAddress();

Kf

1 Like

@kfrajer @GWAK

happy that it works but i remain very confused:

i never saw the Manifest
i suppose that @GWAK is using 2 or 3 phones (6,8,9)
i dont know what is the compiling version
i would like to read some complete code snippet
i have had a look at the src code from Ketai (from which is extracted the code posted) and String “thing” is set to “0.0.0.0” in a for loop (at each loop) so i cannot see why commenting it can change something…And it “returns” the ip, as suggested by @kfrajer

1 Like

@akenaton

This is ‘Ketai library source code’.

static public String getIP() {
String thing = “0.0.0.0”;

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()
          && thing == "0.0.0.0"
          && inetAddress.getHostAddress().matches(
              "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b")) {
        thing = inetAddress.getHostAddress();
      }
       PApplet.println("IP address: " + inetAddress.getHostAddress());
       PApplet.println("thing : " + thing);
    }
  }
} catch (SocketException ex) {
  PApplet.println("SocketException:" + ex.toString());
} catch (NullPointerException nx) {
  PApplet.println("Failed to get any network interfaces...");
}

       //PApplet.println("IP address: " + inetAddress.getHostAddress());
       //PApplet.println("thing : " + thing);
return thing;

}

The source code has been modified as shown below.

// && thing == “0.0.0.0”

I do not know the exact reason. ;;
The obvious thing is that there is an error in the Android 9.0 version of the smartphone.

@GWAK ===
i told you that i have had a look to this code (from the ketai lib src) ; but you dont answer to the others questions and the real explanation is probably here (the Manifest, the version used for compiling and so on…+ the real code you are using ) -

@akenaton

Dear akenaton,

[Use source code / Real code]

import android.os.Bundle;

import ketai.net. ;
import ketai.ui.
;
import oscP5. ;
import netP5.
;
void setup()
{
fullScreen();
orientation(PORTRAIT);
println(KetaiNet.getIP());
}

[Result]
Example1)
target SDK(Manifest Version) : API9 / Smartphone Android 9.0 :: Strange value ip address

Example2)
target SDK(Manifest Version) : API9 / Smartphone Android 8.0 :: Correct ip address

Example3)
target SDK(Manifest Version) : API8.1 / Smartphone Android 9.0 :: Strange value ip address

Example4)
target SDK(Manifest Version) : API7.0 / Smartphone Android 9.0 :: Strange value ip address

Do you understand?

@GWAK ===
not sure to understand:

  • are you using 2 real phones (8,9) for testing?
  • when you commented: thing = “0.0.0.0” how have you done that?Recompiling the library?
1 Like

@akenaton

Hi, Dear akenaton.

  1. Yes, real testing.
  2. I did not create a library, I used only that source.

@GWAK ===

-Real testing WITH TWO REAL DIFFERENT PHONES?

  • Where and how have you used that source? - I cannot see it in the real code you have put

-without recompiling the lib commenting/uncommenting the src code cannot have any effect!

1 Like

@akenaton

Depending on the Android version, the result value is different.