7 Replies Latest reply on Nov 16, 2012 7:44 AM by Gareth Lewis

    How to get mac address of an android device?

      Hi, I am trying to get mac address of android device but in vain. Since macaddr and few other options depend on ifconfig/ipconfig etc, I tried using Ruby Socket but no success.

      Please help

      Thanks!

      Moin

        • Re: How to get mac address of an android device?
          Benedict Kennedy

          Hi Moin,

           

          You can get the MAC address by using the RhoElements' Signal Object's signalEvent.

           

          Documentation on this object and event is available here:

          http://docs.rhomobile.com/rhoelements/signal#events

           

          I hope this helps,

          Ben

            • Re: How to get mac address of an android device?

              Hi Ben,

              Many thanks for reply. I looked into this and in fact earlier but somehow I am confused about implementation.

              I tried but could not knit together everything.

              Signal(Ruby Object) is available but dong this:

              Signal.event = url_for(:action => '/app/Settings/signal_test') or

              Signal.signalEvent = url_for(:action => '/app/Settings/signal_test')

              forcing app to be hanged.

              FYI: Signal.methods has nothing like events or signalEvents.

              Please guide me "how to implement this in rhodes app"?

              Thanks!

              • Re: How to get mac address of an android device?

                Hi Ben,

                I tried with javascript and somehow its working:

                 

                <script type="text/javascript"> 

                      function signal_test(){

                        signal.signalEvent = "Javascript:get_signal_events(%json);";

                      }

                     function get_signal_events(jsonObj){

                       var macaddr = jsonObj.macAddress;

                       if (window.XMLHttpRequest)

                       {

                         var xhr = new window.XMLHttpRequest();

                         xhr.open("GET", '/app/Settings/macaddress?macaddr='+encodeURIComponent(macaddr), true);

                         xhr.send(null);

                       }else

                       {

                         var xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");

                         xmlHttpReq.open("GET", '/app/Settings/macaddress?macaddr='+encodeURIComponent(macaddr), true);

                         xmlHttpReq.send();

                       }

                     }

                    </script>

                 

                    <body onload="signal_test();" >

                     </body>

                 

                Now, since the SignalEvent gives an indication of the signal level and other associated information. Once registered will receive a SignalEvent at regular intervals, as specified by the SignalRefresh configuration setting.

                 

                Is there any way to call is once instead according to SignalRefresh?

                Please throw some light?

                  • Re: How to get mac address of an android device?
                    Benedict Kennedy

                    Hi Moin,

                     

                    If I am trying to find the MAC Address, I will unset the signalEvent parameter after the first signalEvent is fired:

                     

                    function signal_test(){
                              signal.signalEvent = "Javascript:get_signal_events(%json);";
                    }
                    function get_signal_events(jsonObj){
                              var macaddr = jsonObj.macAddress;
                            signal.signalEvent = ""; //Clear the signal event so it doesnt fire again
                              if (window.XMLHttpRequest)
                              {
                                        var xhr = new window.XMLHttpRequest();
                                        xhr.open("GET", '/app/Settings/macaddress?macaddr='+encodeURIComponent(macaddr), true);
                                        xhr.send(null);
                              }else
                              {
                                        var xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
                                        xmlHttpReq.open("GET", '/app/Settings/macaddress?macaddr='+encodeURIComponent(macaddr), true);
                                        xmlHttpReq.send();
                              }
                    }
                    

                     

                    Unfortunately, I don't have enough experience with Ruby to be able to work out the issue with the Ruby code. I have forwarded this onto a colleague, he should respond soon so we will have answers for both approaches.

                     

                    Best regards,

                     

                    Ben

                    • Re: How to get mac address of an android device?

                      Hello Moin,

                       

                      I'm a colleague of Ben's and will try and help you with the Ruby code.  Can you send me the code for controller.rb in the settings application.  I will create a small project myself and see what results I get.

                       

                      Regards,

                       

                      Gareth Lewis

                        • Re: How to get mac address of an android device?

                          Most devices can have more than one MAC address.  WiFi will; USB might; USB to Ethernet will (cradled into an Ethernet cradle;) etc. 

                           

                          WinMobile .NET code will return the MACs as an array of MAC addresses or, if none is established, a placeholder.

                           

                          The placeholder is where an adopted or spoofed MAC will be and commonly looks like 00 11 22 33... or 01 02 03 04... or something showing pattern.

                           

                          Question:    How might that be addressed within JS or Ruby?  This is not a current issue, but just an observation.

                            • Re: How to get mac address of an android device?

                              Hi Carl,

                               

                              At the level that RhoElements or Rhodes Applications run, you don't have control over what connectivity is in use.  Potentially an API could be made that can return what connectivity the application is currently using, e.g. Wi-Fi, 3G, EE, etc, but it doesn't exist now.

                               

                              For Moin's case I believe he is more concerned about the apparent 'hang' that occurs when the signal event is fired.

                               

                              Regards,

                               

                              Gareth