Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;

import android.support.annotation.Nullable;
import android.telephony.TelephonyManager;

public class Main {
    /**
     * Returns the ISO code of the current country
     * @param context Context in which the application is running
     * @return the ISO code of the current country, or null if not found
     */
    @Nullable
    public static String getCountryIso(Context context) {
        if (context != null) {
            TelephonyManager telephonyManager = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);
            if (telephonyManager != null)
                return telephonyManager.getNetworkCountryIso().toLowerCase();
        }
        return null;
    }
}