import java.util.Locale;
import android.content.Context;
import android.provider.Settings;
import android.telephony.TelephonyManager;
publicclass Utils {
privatestaticfinal String TAG = "Utils";
publicstatic Locale checkHandsetLocale(Context ctx) {
boolean EMULATOR = false;
// Disable this block to disable EMULATOR use of this app (enabling is
// useful for testing)
EMULATOR = (Settings.Secure.getString(ctx.getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID) == null);
Locale locale = Locale.getDefault();
String lo = locale.getCountry().toLowerCase();
// Check country: show network country is not the same as locale country
TelephonyManager mTelephonyMgr = (TelephonyManager) ctx
.getSystemService(Context.TELEPHONY_SERVICE);
String country = mTelephonyMgr.getNetworkCountryIso().toLowerCase();
if (country.matches(lo) && !EMULATOR)
return locale;
}
}