Detect if simulator or device

Hi all,

How can I detect if I'm running on the simulator or on a physical device in Android?

Thanks,
Alex

Posts

  • ashalvaashalva GEMember ✭✭✭

    Hi Alex,
    1. It is called Emulator, not Simulator :)
    2. I don`t see the aim to detect if the app is running on Emulator or on real device. Emulators are just for developers to test their apps quite fast, if it works and looks as they want.

    Could you tell the reasons why are you trying to detect above mentioned?

    Regards,
    Shalva

  • Hi Shalva,

    Thanks for your answer, this works great!

    The reason is purely for dev. I have a "DEV" mode in my application where I skip the login page and connect automatically. The dev server to which I connect, is different when on the emulator or on the device.

    Oh and the word "simulator" was actually taken from a Xamarin page directly :) http://developer.xamarin.com/recipes/ios/general/projects/environment_checks/

    Alex

  • ashalvaashalva GEMember ✭✭✭

    Hey Alex,
    Glad I was able to help you.

    For iOS: Simulator
    For Android: Emulator

    Cheers

  • ClausElmannClausElmann DKMember ✭✭

    In VS2015 i found that fing.Contains("vsemu") does the trick

  • DamianSuessDamianSuess USMember ✭✭
    edited August 2016

    @ashalva said:
    2. I don`t see the aim to detect if the app is running on Emulator or on real device. Emulators are just for developers to test their apps quite fast, if it works and looks as they want.

    Could you tell the reasons why are you trying to detect above mentioned?

    Great feedback on this question, thank you everyone.
    If I may add to this, my reasons are for security purposes. Sure if someone is going to break in, they will. It still covers some percent

  • JPatel77JPatel77 ZAMember ✭✭
    edited January 2017

    Works perfectly, thank you!

  • DonCB2BDonCB2B USMember ✭✭✭

    @ashalva said:
    Hi Alex,
    1. It is called Emulator, not Simulator :)
    2. I don`t see the aim to detect if the app is running on Emulator or on real device. Emulators are just for developers to test their apps quite fast, if it works and looks as they want.

    Could you tell the reasons why are you trying to detect above mentioned?

    Regards,
    Shalva

    what's different between simulator and emulator?

  • RyanMendozaRyanMendoza USMember ✭✭

    @DonCB2B said:

    @ashalva said:
    Hi Alex,
    1. It is called Emulator, not Simulator :)
    2. I don`t see the aim to detect if the app is running on Emulator or on real device. Emulators are just for developers to test their apps quite fast, if it works and looks as they want.

    Could you tell the reasons why are you trying to detect above mentioned?

    Regards,
    Shalva

    what's different between simulator and emulator?

    Nothing

  • KhoiVoKhoiVo USMember

    @ashalva said:
    Hi Alex,
    1. It is called Emulator, not Simulator :)
    2. I don`t see the aim to detect if the app is running on Emulator or on real device. Emulators are just for developers to test their apps quite fast, if it works and looks as they want.

    Could you tell the reasons why are you trying to detect above mentioned?

    Regards,
    Shalva

    If you working for a game company like me (our team working with cross platform Xamarin iOS and Android game and UWP game with same code). Thousand user will have a unknown crash on emulator like BlueStack. We tested with a thousand real Android devices and UWP on PC and tablet PC but can not reduce that bug.

  • sheavenssheavens Member

    I came across this while trying to do this myself on iOS, and after some research found this worked for me.

                if (ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.DEVICE)
                {
                    // Running on a device 
                    // return something
                }
                // Running on a Simulator
                // return something else
    
  • ethanwjonesethanwjones Member ✭✭

    Wow thanks, that's helpful! Saving this comment.

  • MarkZhukovskyMarkZhukovsky USMember ✭✭

    Add Xamarin.Essentials to your project and then you can use DeviceInfo.DeviceType : https://docs.microsoft.com/en-us/xamarin/essentials/device-information?context=xamarin/xamarin-forms&tabs=ios#device-type

Sign In or Register to comment.