Last active
February 26, 2017 12:31
-
-
Save mohsenoid/8b0609de1621e6b1728bb9c31d9207af to your computer and use it in GitHub Desktop.
Check Android device Iranian sim-card operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mirhoseini; | |
import android.content.Context; | |
import android.telephony.TelephonyManager; | |
public class IranSimCardUtil { | |
public static String MCI_OPERATOR = "43211"; | |
// Telecommunication Kish | |
public static String TKC_OPERATOR = "43214"; | |
// Mobile Telecommunications Company of Esfahan | |
public static String MTCE_OPERATOR = "43219"; | |
public static String RIGHTEL_OPERATOR = "43220"; | |
public static String TALIYA_OPERATOR = "43232"; | |
public static String IRANCELL_OPERATOR = "43235"; | |
// Telecommunication Company of Iran | |
public static String TCI_OPERATOR = "43270"; | |
static IranianSimCardOperators iranianSimCardOperators = null; | |
/** | |
* Check sim-card operator in Iran such as MTN-Irancell, MCI, Rightel, Taliya, ... | |
* | |
* @param context Context of application | |
* @return | |
*/ | |
public static IranianSimCardOperators getSimCardOperator(Context context) { | |
if (iranianSimCardOperators == null) { | |
TelephonyManager manager = (TelephonyManager) context | |
.getSystemService(Context.TELEPHONY_SERVICE); | |
if (checkSimExistence(context)) { | |
String strSimOperator = manager.getSimOperator(); | |
if (strSimOperator.equals(MCI_OPERATOR)) | |
iranianSimCardOperators = IranianSimCardOperators.MCI; | |
else if (strSimOperator.equals(TKC_OPERATOR)) | |
iranianSimCardOperators = IranianSimCardOperators.TKC; | |
else if (strSimOperator.equals(MTCE_OPERATOR)) | |
iranianSimCardOperators = IranianSimCardOperators.MTCE; | |
else if (strSimOperator.equals(RIGHTEL_OPERATOR)) | |
iranianSimCardOperators = IranianSimCardOperators.RIGHTEL; | |
else if (strSimOperator.equals(TALIYA_OPERATOR)) | |
iranianSimCardOperators = IranianSimCardOperators.TALIYA; | |
else if (strSimOperator.equals(IRANCELL_OPERATOR)) | |
iranianSimCardOperators = IranianSimCardOperators.IRANCELL; | |
else if (strSimOperator.equals(TCI_OPERATOR)) | |
iranianSimCardOperators = IranianSimCardOperators.TCI; | |
else { | |
iranianSimCardOperators = IranianSimCardOperators.UNKNOWN; | |
} | |
} else { | |
iranianSimCardOperators = null; | |
} | |
} | |
return iranianSimCardOperators; | |
} | |
/** | |
* Check if sim-card exist | |
* | |
* @param context Context of application | |
* @return | |
*/ | |
public static boolean checkSimExistence(Context context) { | |
TelephonyManager manager = (TelephonyManager) context | |
.getSystemService(Context.TELEPHONY_SERVICE); | |
return manager.getSimState() == TelephonyManager.SIM_STATE_READY ? true | |
: false; | |
} | |
public enum IranianSimCardOperators { | |
MCI, TKC, MTCE, TALIYA, IRANCELL, TCI, RIGHTEL, UNKNOWN | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment