5

I've seen this question asked many times all over the web but there does not appear to be a comprehensive answer anywhere.

I have created a J2ME app which needs to detect the network connection type (so it can connect to a different resource if connected via Wi-Fi).

There is an answer here that pertains to Nokia devices and one here that pertains to BlackBerry devices, but I am also developing for:

  • Huawei
  • Tecno
  • Samsung
  • Motorola
  • LG

The Nokia solution appears to be to use System.getProperty("com.nokia.network.access"), so does anyone know what the equivalents of this are for the other device manufacturers?

Community
  • 1
  • 1
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
  • In case it isn't possible to determine the connection type using `System.getProperty()`, one possible alternative could be to detect the device's IP address serverside - see http://www.javameblog.com/2007/12/how-to-get-ip-address-of-mobile-using.html - but you would need to know which IP address ranges corresponded to which mobile network operators (which could presumably change over time, so it would more appropriate to do all that stuff serverside and just report back to the mobile whether it is using a mobile connection or not - then the mobile could use that connection info as required). – ban-geoengineering Apr 03 '15 at 09:46
  • MIDP does not have API to do that, period. Nokia might provide some 'hacks' with system properties, while most other vendors do not, and there's no standard for it. J2ME struggled to provide consistent behavior even for MIDP, then what can you expect from extra thing? – Mixaz Apr 10 '15 at 21:55

1 Answers1

0

I think you may be expecting too much from MIDP. As you no doubt have realized, it's not possible to get connection type using standard JavaME API's, so you rely on specialized options on different brands, as you've also found.

You may need to look for an alternative solution. If you tell exactly what it is you want to do, then maybe there are some other clever "hacks".

If I understand correctly, you want to connect to a WAN IP if connected with GPRS/3G and a LAN IP if connected with Wi-Fi? In that case, if it was me, I would simply make sure the LAN IP was a static one, and then always attempt to reach that one first. If you're connected with Wi-Fi, you will be able to reach it. If not, it will simply be unreachable, and then you can proceed to reaching the WAN IP address.

mr_lou
  • 1,910
  • 2
  • 14
  • 26
  • Other proprietary solutions (in addition to Nokia's) may exist, so hopefully another developer may come forward with information on those. The detection is required so that if it's a mobile connection, content specific to the mobile operator is loaded, otherwise (for a Wi-Fi connection) other static content is loaded - so I don't think your suggestion is good for me. – ban-geoengineering Apr 07 '15 at 14:32
  • Samsung MIGHT have a system property like Nokia, but generally only Nokia implemented and added to the specification. So I would be very surprised if you find any solution for other platforms. I cross my fingers for you though. I'm rather curious myself, but I don't think it's possible sadly. – mr_lou Apr 07 '15 at 16:50