Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.os.Build;

public class Main {
    public static final String EMULATOR_LOCALHOST = "10.0.2.2:8081";
    public static final String GENYMOTION_LOCALHOST = "10.0.3.2:8081";
    public static final String DEVICE_LOCALHOST = "localhost:8081";

    public static String getServerHost() {
        // Since genymotion runs in vbox it use different hostname to refer to adb host.
        // We detect whether app runs on genymotion and replace js bundle server hostname accordingly

        if (isRunningOnGenymotion()) {
            return GENYMOTION_LOCALHOST;
        }

        if (isRunningOnStockEmulator()) {
            return EMULATOR_LOCALHOST;
        }

        return DEVICE_LOCALHOST;
    }

    private static boolean isRunningOnGenymotion() {
        return Build.FINGERPRINT.contains("vbox");
    }

    private static boolean isRunningOnStockEmulator() {
        return Build.FINGERPRINT.contains("generic");
    }
}