0

I'm building a project with Nativescript-Vue. I have standard a setup with Webpack.

I understand that i can pass different vars, using something like this:

tns build android --bundle --env.development --env.property=value

How can i "distinguish" between the two different platforms(emulator and a real device, they are both "development"), in order to pass different API url's?

i.brod
  • 3,993
  • 11
  • 38
  • 74

2 Answers2

1

You can check the Build properties from android.os.Build and see if Build.BRAND.startsWith("generic") or Build.DEVICE.startsWith("generic")) or Build.PRODUCT.contains("emulator").

You may refer to few more properties as described here.

Narendra
  • 4,514
  • 2
  • 21
  • 38
1

You can do something like this,

        if (isIOS) {
            const description = String(NSString.stringWithUTF8String(NXGetLocalArchInfo()[0].description));
            this.isSimulator = description.indexOf("x86") !== -1 || description.indexOf("i386") !== -1;
        }
        if (isAndroid) {
            this.isSimulator = android.os.Build.FINGERPRINT.startsWith("generic")
                || android.os.Build.FINGERPRINT.startsWith("unknown")
                || android.os.Build.MODEL.indexOf("google_sdk") !== -1
                || android.os.Build.MODEL.indexOf("Emulator") !== -1
                || android.os.Build.MODEL.indexOf("Android SDK built for x86") !== -1
                || android.os.Build.MANUFACTURER.indexOf("Genymotion") !== -1
                || (android.os.Build.BRAND.startsWith("generic") && android.os.Build.DEVICE.startsWith("generic"))
                || android.os.Build.PRODUCT === "google_sdk";
        }

The Android version is almost same as the one @Narendra linked in his answer but more of the NativeScript / JavaScript version.

Playground Sample

Manoj
  • 21,753
  • 3
  • 20
  • 41