Copy link to clipboard
Copied
I'm trying to get the MAC address of the user's device in Adobe AIR. This is the code I'm using.
public function getDeviceMac():String {
return NetworkInfo.networkInfo.findInterfaces()[0].hardwareAddress.toString();
}
That function works ok in the PC (or when testing in the PC with ADL Mobile),
but in the iPad 2 or in an Android device (Acer Iconia A500) I get an error
about the property not existing. I suppose it's not implemented in the mobile
versions of AIR. It would be nice if it were implemented in future versions.
Is there any workaround for this?
I'm just seeking a way to uniquely identify a device, so is there
an alternative unique identifier I can get from AIR programatically
(maybe the UDID?), if it's not possible to get the MAC?
Thanks for your help!
Hi,
You'll have to iterate throught all the interfaces available and then find the hardwareAddress.
NetworkInfo.networkInfo.findInterfaces()[1].hardwareAddress.toString( );
Also, for Android, you'll have to specify ACCESS_NETWORK_STATE and ACCESS_WIFI_STATE permissions also in your application descriptor as following.
<android>
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET"/>
<!--The ACCESS_NETWORK_ST
...Copy link to clipboard
Copied
Hi,
You'll have to iterate throught all the interfaces available and then find the hardwareAddress.
NetworkInfo.networkInfo.findInterfaces()[1].hardwareAddress.toString( );
Also, for Android, you'll have to specify ACCESS_NETWORK_STATE and ACCESS_WIFI_STATE permissions also in your application descriptor as following.
<android>
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET"/>
<!--The ACCESS_NETWORK_STATE and ACCESS_WIFI_STATE permissions should be toggled
together in order to use AIR's NetworkInfo APIs-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
</manifest>
]]></manifestAdditions>
</android>
-Pahup
Copy link to clipboard
Copied
Thanks for your answer. I already had both of those permissions enabled in AIR Android, but I assumed since both iPad and Android devices I'm targetting are WiFi only (no 3G), that there would be only one network interface. I've tried looking for all network interfaces, and I could find the MAC of the Android device, but could not do the same in the iPad 2.
This is the code I've used:
var vNetworkInterfaces:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
for each (var networkInterface:NetworkInterface in vNetworkInterfaces) {
try {trace(networkInterface.hardwareAddress);}
catch (e:Error) {}
}
That way I got the MAC in Android, but still, in the iPad 2 I get this error in the first line (the one that executes "findInterfaces();"):
Error #1009: Cannot access a property or method of a null object reference.
So it seems networkInfo.findInterfaces() is not implemented in iOS. I tried getting the value of:
NetworkInfo.isSupported
And the value of that is true in Android but false in the iPad 2. So it seems NetworkInfo is not supported in iOS
Is there any other way in iOS to get a unique identifier for the device? (it doesn't have to be the MAC)
Copy link to clipboard
Copied
yes, NetworkInfo on iOS AIR is not supported.
Request you to log a request for it @ ideas.adobe.com
-Thanks
Pahup
Copy link to clipboard
Copied
Hello,
i am also facing such type of problem in detecting the netowrk state in ipad.
In my application there are two modes available
1. Online
2. Offline
I was using the NetworkInfo.networkInfo.findInterfaces() API to find weather my user is in Online mode or in Offline mode. This API is working very well in my Android build however when i install app in ipad, my app was not able to find any network state.
Can you please suggest me a way by which i can find this in ipad or in iphone?
You can find the code here :
var interfaces:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
for(var i:uint = 0; i < interfaces.length; i++)
{
if(interfaces.name.toLowerCase() == "wifi" && interfaces.active) {
GlobalVaribales.IS_OFFLINE = false;
break;
} else if(interfaces.name.toLowerCase() == "mobile" && interfaces.active) {
GlobalVaribales.IS_OFFLINE = false;
break;
}
else if(interfaces.displayName == 'Local Area Connection' && interfaces.active)
{
GlobalVaribales.IS_OFFLINE = false;
break;
}
}
Copy link to clipboard
Copied
Hi neel_229. With the new Native Extensions feature of AIR 3.0+ you can use the NetworkInterface native extension for iOS to get the same functionality:
http://www.adobe.com/es/devnet/air/native-extensions-for-air/extensions/networkinfo.html
The process to get it working is a little convoluted but it works.
Take a look at this page to learn how to use Native Extensions:
http://help.adobe.com/en_US/air/build/WS597e5dadb9cc1e0253f7d2fc1311b491071-8000.html
Since this extension creates a class with the same name as the existing flash.net.NetworkInfo
it will collide if you want to use both (for cross-platform compatibility in iOS and Android
with the same code). I've managed to use both by not importing their classes
but calling them by their fully qualified path and using generic Objects for the vectors.
See below:
var vNetworkInterfaces:Object;
if (flash.net.NetworkInfo.isSupported)
{
trace('Getting MAC from NetworkInfo (AIR)');
vNetworkInterfaces = getDefinitionByName('flash.net.NetworkInfo')['networkInfo']['findInterfaces']();
}
else
{
trace('Getting MAC from NetworkInfo (ANE)');
vNetworkInterfaces = getDefinitionByName('com.adobe.nativeExtensions.Networkinfo.NetworkInfo')['networkInfo']['findInterfaces']();
}
for each (var networkInterface:Object in vNetworkInterfaces)
{
// Do your networkInterface stuff here. Use the notation networkInterface['property'] to avoid warnings
}
Hope this helps.
Copy link to clipboard
Copied
i'm getting
ArgumentError: Error #3500: The extension context does not have a method with the name getInterfaces.
at flash.external::ExtensionContext/call()
at com.adobe.nativeExtensions.Networkinfo::NetworkInfo/findInterfaces()[/Users/gangwar/Documents/Adobe Flash Builder 4.5/NetworkInfoActionScriptLibrary/src/com/adobe/nativeExtensions/Networkinfo/NetworkInfo.as:70]
at com.adobe.nativeExtensions.Networkinfo::NetworkInfo/findInterfaces()
Anyone else getting this?
Copy link to clipboard
Copied
Have you added the Native Extension in your "name-app.xml" descriptor?
Copy link to clipboard
Copied
i figured out what my problem was. the ExtInitializer of the NetworkInfo conflicts with another native extension (iOS in Mail extension). Disabling the in Mail extension fixed the problem.
I think developers of native extensions need to ensure their extension works no matter what other native extensions people are using.
Copy link to clipboard
Copied
Hey,
This is an old thread but hoping to get some support.
I am running into the same issue with the call to getInterfaces mentioned by K2xL.com
As far as I know, I am not using the iOS in Mail extension but perhaps it's conflicting with one of my other ANEs (which I cannot disabled)
But I'm not seeing any such errors anywhere at the moment.
Thanks!