Retrieve IP address in Android

141 views
Skip to first unread message

Alf Stockton

unread,
Jan 26, 2016, 8:29:53 AM1/26/16
to phonegap
I have created the attached html which all works as expected except that the IP address does not display. I have installed the plugin.
Please tell me where I have gone wrong.

index.html

mharr

unread,
Jan 26, 2016, 10:27:15 AM1/26/16
to phonegap
IT does not look like your plugin is installed.  There should be a link for networkinterface.js on your web page.

Alf Stockton

unread,
Jan 26, 2016, 10:30:33 AM1/26/16
to phon...@googlegroups.com

It is installed & works sometimes but not consistently.

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to a topic in the Google Groups "phonegap" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phonegap/ImFua9KAAGE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phonegap+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kerri Shotts

unread,
Jan 26, 2016, 3:30:38 PM1/26/16
to phonegap
Care to share your config.xml? And which version(s) of plugin(s) you are using?

Alf Stockton

unread,
Jan 27, 2016, 2:49:37 AM1/27/16
to phon...@googlegroups.com
I hope that the following sheds more light on my problem.
cordova -v
5.3.1
alf@debian:~/Develop/cordova/AlfGD$ cordova plugins ls
com.pylonproducts.wifiwizard 0.2.9 "WifiWizard"
cordova-plugin-network-information 1.2.0 "Network Information"
cordova-plugin-networkinterface 1.0.8 "NetworkInterface"
cordova-plugin-websocket 0.9.2 "WebSocket for Android"
cordova-plugin-whitelist 1.0.0 "Whitelist"

Regards,
Alf Stockton.       www.stockton.co.za

config.xml

Alf Stockton

unread,
Jan 27, 2016, 6:11:16 AM1/27/16
to phon...@googlegroups.com
I have subsiquently done some upgrading and now I have
cordova -v
5.4.1
alf@debian:~/Develop/cordova/AlfGD$ cordova plugins list
cordova-plugin-network-information 1.2.1-dev "Network Information"
cordova-plugin-networkinterface 1.0.8 "NetworkInterface"
cordova-plugin-websocket 0.12.0 "WebSocket for Android"
cordova-plugin-whitelist 1.2.2-dev "Whitelist"


Regards,
Alf Stockton.       www.stockton.co.za
config.xml

mharr

unread,
Jan 27, 2016, 7:18:48 AM1/27/16
to phonegap
Have you added the link for networkinterface.js to your Html file?  Your file attachment in your original message did not have it.  You will not be able to call the js functions for the plugin without it.

Alf Stockton

unread,
Jan 27, 2016, 7:49:25 AM1/27/16
to phon...@googlegroups.com
I have now added that .js, see the attached, but fail to understand why
 it previously would work sometimes but not everytime.
On testing including that js made no difference as it is still unreliable.

Regards,
Alf Stockton.       www.stockton.co.za
index.html

Alf Stockton

unread,
Jan 28, 2016, 4:40:24 AM1/28/16
to phon...@googlegroups.com
Adding
setTimeout(NetworkIP, 500);
seems to have done the trick but will carry on testing.

Regards,
Alf Stockton.       www.stockton.co.za
index.html
Message has been deleted

Alf Stockton

unread,
Jan 28, 2016, 7:42:22 AM1/28/16
to phon...@googlegroups.com

Thank you

On 28 Jan 2016 14:39, "mharr" <ma...@harr.us> wrote:
<script type="text/javascript">
$(function() {
document.addEventListener("deviceready", function() {
networkinterface.getIPAddress(function (ip) {
document.getElementById("openclose").innerHTML=ip; 
}, 
function(err) {
document.getElementById("openclose").innerHTML="Failed Getting IP";
});
}, false)
});
</script>


Enter code here..At least based on your attached sample page, you are not waiting for deviceready event. Your setTimeout effectively does that because it throws your js function on the stack after the rest of scripts run.  But you would probably be better off properly using deviceready:

mharr

unread,
Jan 28, 2016, 7:47:02 AM1/28/16
to phonegap
At least based on your attached sample page, you are not waiting for deviceready event. Your setTimeout effectively does that because it throws your js function on the stack after the rest of scripts run.  But you would probably be better off properly using deviceready:

<script type="text/javascript">
$(function() {
document.addEventListener("deviceready", function() {
networkinterface.getIPAddress(function (ip) {
document.getElementById("openclose").innerHTML=ip; 
}, 
function(err) {
document.getElementById("openclose").innerHTML="Failed Getting IP";
});
}, false)
});
</script>

Reply all
Reply to author
Forward
0 new messages