Detect if connected to via WiFi or 3G

The place to discuss anything and everything about running your LiveCode on Android

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
rblackmore245
Posts: 67
Joined: Fri Jun 12, 2015 9:42 am

Detect if connected to via WiFi or 3G

Post by rblackmore245 » Fri Jun 12, 2015 6:04 pm

Is there anyway to detect if the device is connected via WIFI not 3G

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Detect if connected to via WiFi or 3G

Post by Simon » Fri Jun 12, 2015 8:10 pm

Hi rblackmore245,
Try iphoneSetReachabilityTarget I haven't used it in a while but I think it tells you how you are connected.

Simon
Edit; ooops, you want Android. Sorry I don't have an answer for that one.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

rblackmore245
Posts: 67
Joined: Fri Jun 12, 2015 9:42 am

Re: Detect if connected to via WiFi or 3G

Post by rblackmore245 » Mon Jun 29, 2015 2:42 pm

Anyone know of a way of doing this in LC ?.

Seems a bit silly that they would have a function for IOS but not for Android.

rblackmore245
Posts: 67
Joined: Fri Jun 12, 2015 9:42 am

Re: Detect if connected to via WiFi or 3G

Post by rblackmore245 » Mon Jun 29, 2015 3:46 pm

For anyone who wants to do this I have found a work around.. by using a third party called http://ipinfo.io its open source which outputs a json which displays the company for the IP and host name, and with a simple PHP script I was able to look for the UK suppliers of mobile networks as in the UK there are only a few.

PHP script which you would place on your website

<?
$ip=$_SERVER['REMOTE_ADDR'];
function get_asn($ip) {
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}"));
return $details->org;
}
echo get_asn($ip);
?>




on mouseUp
put empty into Mobile
put URL "http://www.yourwebsite.co.uk/myip.php" into parser


if offset("Hutchison", parser) > 0 then
put "Three Mobile" into Mobile
end if
if offset("VODAFONE", parser) > 0 then
put "Vodafone" into Mobile
end if
if offset("Orange", parser) > 0 then
put "Orange" into Mobile
end if

if offset("Telefonica", parser) > 0 then
put "O2" into Mobile
end if
if Mobile <> empty then
answer(" Your On a Mobile " & Mobile) with "Ok"
else
answer("Could not detect 3G you must be on WIFI") with "ok"
end if
end mouseUp

Have tried it on Three mobile UK, Orange ( Now EE ), Vodafone UK, O2 UK, hope this is useful to someone :o)

Post Reply

Return to “Android Deployment”