Java Code Examples for android.telephony.TelephonyManager#SIM_STATE_ABSENT
The following examples show how to use
android.telephony.TelephonyManager#SIM_STATE_ABSENT .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: HttpInfo File: Net.java License: Apache License 2.0 | 6 votes |
public static boolean hasSimCard(Context context) { boolean result = true; try { TelephonyManager telMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); int simState = telMgr.getSimState(); switch (simState) { case TelephonyManager.SIM_STATE_ABSENT: result = false; break; case TelephonyManager.SIM_STATE_UNKNOWN: result = false; break; default: break; } } catch (Exception e) { //ignore } return result; }
Example 2
Source Project: react-native-callkeep File: RNCallKeepModule.java License: ISC License | 6 votes |
@ReactMethod public void checkDefaultPhoneAccount(Promise promise) { if (!isConnectionServiceAvailable() || !hasPhoneAccount()) { promise.resolve(true); return; } if (!Build.MANUFACTURER.equalsIgnoreCase("Samsung")) { promise.resolve(true); return; } boolean hasSim = telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT; boolean hasDefaultAccount = telecomManager.getDefaultOutgoingPhoneAccount("tel") != null; promise.resolve(!hasSim || hasDefaultAccount); }
Example 3
Source Project: MobileInfo File: SimCardInfo.java License: Apache License 2.0 | 6 votes |
/** * 判断是否包含SIM卡 * * @param context 上下文 * @return 状态 是否包含SIM卡 */ private static boolean hasSimCard(Context context) { boolean result = true; try { TelephonyManager telMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); int simState = telMgr.getSimState(); switch (simState) { case TelephonyManager.SIM_STATE_ABSENT: result = false; break; case TelephonyManager.SIM_STATE_UNKNOWN: result = false; break; default: break; } } catch (Exception e) { } return result; }
Example 4
Source Project: under-the-hood File: TypeTranslators.java License: Apache License 2.0 | 6 votes |
/** * @param simState expected to be from {@link TelephonyManager#getSimState()} * @return human-readable state */ public static String translateSimState(int simState) { switch (simState) { case TelephonyManager.SIM_STATE_READY: return "STATE_READY"; case TelephonyManager.SIM_STATE_PUK_REQUIRED: case TelephonyManager.SIM_STATE_NETWORK_LOCKED: case TelephonyManager.SIM_STATE_PIN_REQUIRED: return "STATE_LOCKED (" + simState + ")"; case TelephonyManager.SIM_STATE_ABSENT: return "STATE_ABSENT"; default: case TelephonyManager.SIM_STATE_UNKNOWN: return "UNKNOWN (" + simState + ")"; } }
Example 5
Source Project: DoingDaily File: DeviceUtil.java License: Apache License 2.0 | 6 votes |
/** * @param context * @return */ public static String getIMSI(Context context) { String imsi = "00000000000000"; TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String model = Build.MANUFACTURER + Build.MODEL; if (tm == null || (model.toLowerCase().contains("htc") && (tm.getSimState() == TelephonyManager.SIM_STATE_ABSENT || tm.getSimState() == TelephonyManager.SIM_STATE_UNKNOWN))) { return imsi; } String imsiTmp = tm.getSubscriberId(); if (!TextUtils.isEmpty(imsiTmp)) { imsi = imsiTmp; } return imsi; }
Example 6
Source Project: DualSIMCard File: TelInfo.java License: Apache License 2.0 | 6 votes |
private static boolean getSIMStateBySlot(Context context, String predictedMethodName, int slotID) throws ITgerMethodNotFoundException { boolean isReady = false; TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); try { Class<?> telephonyClass = Class.forName(telephony.getClass().getName()); Class<?>[] parameter = new Class[1]; parameter[0] = int.class; Method getSimState = telephonyClass.getMethod(predictedMethodName, parameter); Object[] obParameter = new Object[1]; obParameter[0] = slotID; Object ob_phone = getSimState.invoke(telephony, obParameter); if (ob_phone != null) { int simState = Integer.parseInt(ob_phone.toString()); telInf.sim2_STATE = simState(simState); if ((simState != TelephonyManager.SIM_STATE_ABSENT) && (simState != TelephonyManager.SIM_STATE_UNKNOWN)) { isReady = true; } } } catch (Exception e) { e.printStackTrace(); throw new ITgerMethodNotFoundException(predictedMethodName); } return isReady; }
Example 7
Source Project: RairDemo File: NetworkConnUtil.java License: Apache License 2.0 | 5 votes |
/** * 检查sim卡状态 * * @return */ public static boolean checkSimState(Context context) { TelephonyManager tm = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); if (tm.getSimState() == TelephonyManager.SIM_STATE_ABSENT || tm.getSimState() == TelephonyManager.SIM_STATE_UNKNOWN) { return false; } return true; }
Example 8
Source Project: country-picker-android File: CountryPicker.java License: MIT License | 5 votes |
public Country getCountryFromSIM() { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null && telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT) { return getCountryByISO(telephonyManager.getSimCountryIso()); } return null; }
Example 9
Source Project: TelePlus-Android File: CancelAccountDeletionActivity.java License: GNU General Public License v2.0 | 4 votes |
@Override public void onNextPressed() { if (getParentActivity() == null || nextPressed) { return; } TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE; boolean allowCall = true; if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) { //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; //boolean allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED; /*if (checkPermissions) { permissionsItems.clear(); if (!allowCall) { permissionsItems.add(Manifest.permission.READ_PHONE_STATE); } if (!allowSms) { permissionsItems.add(Manifest.permission.RECEIVE_SMS); } if (!permissionsItems.isEmpty()) { SharedPreferences preferences = MessagesController.getGlobalMainSettings(); if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.RECEIVE_SMS)) { preferences.edit().putBoolean("firstlogin", false).commit(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); if (permissionsItems.size() == 2) { builder.setMessage(LocaleController.getString("AllowReadCallAndSms", R.string.AllowReadCallAndSms)); } else if (!allowSms) { builder.setMessage(LocaleController.getString("AllowReadSms", R.string.AllowReadSms)); } else { builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall)); } permissionsDialog = showDialog(builder.create()); } else { getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6); } return; } }*/ } final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode(); req.allow_flashcall = false;//simcardAvailable && allowCall; req.hash = hash; if (req.allow_flashcall) { try { @SuppressLint("HardwareIds") String number = tm.getLine1Number(); if (!TextUtils.isEmpty(number)) { req.current_number = phone.contains(number) || number.contains(phone); if (!req.current_number) { req.allow_flashcall = false; } } else { req.current_number = false; } } catch (Exception e) { req.allow_flashcall = false; FileLog.e(e); } } final Bundle params = new Bundle(); params.putString("phone", phone); nextPressed = true; ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { nextPressed = false; if (error == null) { fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response); } else { errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req); } } }); } }, ConnectionsManager.RequestFlagFailOnServerErrors); }
Example 10
Source Project: TelePlus-Android File: PaymentFormActivity.java License: GNU General Public License v2.0 | 4 votes |
@SuppressLint("HardwareIds") public void fillNumber(String number) { try { TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); boolean allowCall = true; boolean allowSms = true; if (number != null || tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) { if (Build.VERSION.SDK_INT >= 23) { allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED; } if (number != null || allowCall || allowSms) { if (number == null) { number = PhoneFormat.stripExceptNumbers(tm.getLine1Number()); } String textToSet = null; boolean ok = false; if (!TextUtils.isEmpty(number)) { if (number.length() > 4) { for (int a = 4; a >= 1; a--) { String sub = number.substring(0, a); String country = codesMap.get(sub); if (country != null) { ok = true; textToSet = number.substring(a, number.length()); inputFields[FIELD_PHONECODE].setText(sub); break; } } if (!ok) { textToSet = number.substring(1, number.length()); inputFields[FIELD_PHONECODE].setText(number.substring(0, 1)); } } if (textToSet != null) { inputFields[FIELD_PHONE].setText(textToSet); inputFields[FIELD_PHONE].setSelection(inputFields[FIELD_PHONE].length()); } } } } } catch (Exception e) { FileLog.e(e); } }
Example 11
Source Project: TelePlus-Android File: LoginActivity.java License: GNU General Public License v2.0 | 4 votes |
public void fillNumber() { try { TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); if (tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) { boolean allowCall = true; boolean allowSms = true; if (Build.VERSION.SDK_INT >= 23) { allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED; if (checkShowPermissions && !allowCall && !allowSms) { permissionsShowItems.clear(); if (!allowCall) { permissionsShowItems.add(Manifest.permission.READ_PHONE_STATE); } if (!allowSms) { permissionsShowItems.add(Manifest.permission.RECEIVE_SMS); if (Build.VERSION.SDK_INT >= 23) { permissionsShowItems.add(Manifest.permission.READ_SMS); } } if (!permissionsShowItems.isEmpty()) { SharedPreferences preferences = MessagesController.getGlobalMainSettings(); if (preferences.getBoolean("firstloginshow", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.RECEIVE_SMS)) { preferences.edit().putBoolean("firstloginshow", false).commit(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setMessage(LocaleController.getString("AllowFillNumber", R.string.AllowFillNumber)); permissionsShowDialog = showDialog(builder.create()); } else { getParentActivity().requestPermissions(permissionsShowItems.toArray(new String[permissionsShowItems.size()]), 7); } } return; } } if (!newAccount && (allowCall || allowSms)) { String number = PhoneFormat.stripExceptNumbers(tm.getLine1Number()); String textToSet = null; boolean ok = false; if (!TextUtils.isEmpty(number)) { if (number.length() > 4) { for (int a = 4; a >= 1; a--) { String sub = number.substring(0, a); String country = codesMap.get(sub); if (country != null) { ok = true; textToSet = number.substring(a, number.length()); codeField.setText(sub); break; } } if (!ok) { textToSet = number.substring(1, number.length()); codeField.setText(number.substring(0, 1)); } } if (textToSet != null) { phoneField.requestFocus(); phoneField.setText(textToSet); phoneField.setSelection(phoneField.length()); } } } } } catch (Exception e) { FileLog.e(e); } }
Example 12
Source Project: TelePlus-Android File: CancelAccountDeletionActivity.java License: GNU General Public License v2.0 | 4 votes |
@Override public void onNextPressed() { if (getParentActivity() == null || nextPressed) { return; } TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE; boolean allowCall = true; if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) { //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; //boolean allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED; /*if (checkPermissions) { permissionsItems.clear(); if (!allowCall) { permissionsItems.add(Manifest.permission.READ_PHONE_STATE); } if (!allowSms) { permissionsItems.add(Manifest.permission.RECEIVE_SMS); } if (!permissionsItems.isEmpty()) { SharedPreferences preferences = MessagesController.getGlobalMainSettings(); if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.RECEIVE_SMS)) { preferences.edit().putBoolean("firstlogin", false).commit(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); if (permissionsItems.size() == 2) { builder.setMessage(LocaleController.getString("AllowReadCallAndSms", R.string.AllowReadCallAndSms)); } else if (!allowSms) { builder.setMessage(LocaleController.getString("AllowReadSms", R.string.AllowReadSms)); } else { builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall)); } permissionsDialog = showDialog(builder.create()); } else { getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6); } return; } }*/ } final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode(); req.allow_flashcall = false;//simcardAvailable && allowCall; req.hash = hash; if (req.allow_flashcall) { try { @SuppressLint("HardwareIds") String number = tm.getLine1Number(); if (!TextUtils.isEmpty(number)) { req.current_number = phone.contains(number) || number.contains(phone); if (!req.current_number) { req.allow_flashcall = false; } } else { req.current_number = false; } } catch (Exception e) { req.allow_flashcall = false; FileLog.e(e); } } final Bundle params = new Bundle(); params.putString("phone", phone); nextPressed = true; ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { nextPressed = false; if (error == null) { fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response); } else { errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req); } } }); } }, ConnectionsManager.RequestFlagFailOnServerErrors); }
Example 13
Source Project: TelePlus-Android File: PaymentFormActivity.java License: GNU General Public License v2.0 | 4 votes |
@SuppressLint("HardwareIds") public void fillNumber(String number) { try { TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); boolean allowCall = true; boolean allowSms = true; if (number != null || tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) { if (Build.VERSION.SDK_INT >= 23) { allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED; } if (number != null || allowCall || allowSms) { if (number == null) { number = PhoneFormat.stripExceptNumbers(tm.getLine1Number()); } String textToSet = null; boolean ok = false; if (!TextUtils.isEmpty(number)) { if (number.length() > 4) { for (int a = 4; a >= 1; a--) { String sub = number.substring(0, a); String country = codesMap.get(sub); if (country != null) { ok = true; textToSet = number.substring(a, number.length()); inputFields[FIELD_PHONECODE].setText(sub); break; } } if (!ok) { textToSet = number.substring(1, number.length()); inputFields[FIELD_PHONECODE].setText(number.substring(0, 1)); } } if (textToSet != null) { inputFields[FIELD_PHONE].setText(textToSet); inputFields[FIELD_PHONE].setSelection(inputFields[FIELD_PHONE].length()); } } } } } catch (Exception e) { FileLog.e(e); } }
Example 14
Source Project: TelePlus-Android File: LoginActivity.java License: GNU General Public License v2.0 | 4 votes |
public void fillNumber() { try { TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); if (tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) { boolean allowCall = true; boolean allowSms = true; if (Build.VERSION.SDK_INT >= 23) { allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED; if (checkShowPermissions && !allowCall && !allowSms) { permissionsShowItems.clear(); if (!allowCall) { permissionsShowItems.add(Manifest.permission.READ_PHONE_STATE); } if (!allowSms) { permissionsShowItems.add(Manifest.permission.RECEIVE_SMS); if (Build.VERSION.SDK_INT >= 23) { permissionsShowItems.add(Manifest.permission.READ_SMS); } } if (!permissionsShowItems.isEmpty()) { SharedPreferences preferences = MessagesController.getGlobalMainSettings(); if (preferences.getBoolean("firstloginshow", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.RECEIVE_SMS)) { preferences.edit().putBoolean("firstloginshow", false).commit(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setMessage(LocaleController.getString("AllowFillNumber", R.string.AllowFillNumber)); permissionsShowDialog = showDialog(builder.create()); } else { getParentActivity().requestPermissions(permissionsShowItems.toArray(new String[permissionsShowItems.size()]), 7); } } return; } } if (!newAccount && (allowCall || allowSms)) { String number = PhoneFormat.stripExceptNumbers(tm.getLine1Number()); String textToSet = null; boolean ok = false; if (!TextUtils.isEmpty(number)) { if (number.length() > 4) { for (int a = 4; a >= 1; a--) { String sub = number.substring(0, a); String country = codesMap.get(sub); if (country != null) { ok = true; textToSet = number.substring(a, number.length()); codeField.setText(sub); break; } } if (!ok) { textToSet = number.substring(1, number.length()); codeField.setText(number.substring(0, 1)); } } if (textToSet != null) { phoneField.requestFocus(); phoneField.setText(textToSet); phoneField.setSelection(phoneField.length()); } } } } } catch (Exception e) { FileLog.e(e); } }
Example 15
Source Project: px-android File: SimCardUtils.java License: MIT License | 4 votes |
public static boolean deviceHasSimCard(final Context context) { final TelephonyManager tm = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE); return tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT; }
Example 16
Source Project: Telegram-FOSS File: CancelAccountDeletionActivity.java License: GNU General Public License v2.0 | 4 votes |
@Override public void onNextPressed() { if (getParentActivity() == null || nextPressed) { return; } TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE; boolean allowCall = true; if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) { //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; /*if (checkPermissions) { permissionsItems.clear(); if (!allowCall) { permissionsItems.add(Manifest.permission.READ_PHONE_STATE); } if (!permissionsItems.isEmpty()) { SharedPreferences preferences = MessagesController.getGlobalMainSettings(); if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE)) { preferences.edit().putBoolean("firstlogin", false).commit(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall)); permissionsDialog = showDialog(builder.create()); } else { getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6); } return; } }*/ } final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode(); req.hash = hash; req.settings = new TLRPC.TL_codeSettings(); req.settings.allow_flashcall = false;//simcardAvailable && allowCall; req.settings.allow_app_hash = ApplicationLoader.hasPlayServices; SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); if (req.settings.allow_app_hash) { preferences.edit().putString("sms_hash", BuildVars.SMS_HASH).commit(); } else { preferences.edit().remove("sms_hash").commit(); } if (req.settings.allow_flashcall) { try { @SuppressLint("HardwareIds") String number = tm.getLine1Number(); if (!TextUtils.isEmpty(number)) { req.settings.current_number = PhoneNumberUtils.compare(phone, number); if (!req.settings.current_number) { req.settings.allow_flashcall = false; } } else { req.settings.current_number = false; } } catch (Exception e) { req.settings.allow_flashcall = false; FileLog.e(e); } } final Bundle params = new Bundle(); params.putString("phone", phone); nextPressed = true; ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { nextPressed = false; if (error == null) { fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response); } else { errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req); } }), ConnectionsManager.RequestFlagFailOnServerErrors); }
Example 17
Source Project: Telegram-FOSS File: PaymentFormActivity.java License: GNU General Public License v2.0 | 4 votes |
@SuppressLint("HardwareIds") public void fillNumber(String number) { try { TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); boolean allowCall = true; boolean allowSms = true; if (number != null || tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) { if (Build.VERSION.SDK_INT >= 23) { allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; } if (number != null || allowCall) { if (number == null) { number = PhoneFormat.stripExceptNumbers(tm.getLine1Number()); } String textToSet = null; boolean ok = false; if (!TextUtils.isEmpty(number)) { if (number.length() > 4) { for (int a = 4; a >= 1; a--) { String sub = number.substring(0, a); String country = codesMap.get(sub); if (country != null) { ok = true; textToSet = number.substring(a); inputFields[FIELD_PHONECODE].setText(sub); break; } } if (!ok) { textToSet = number.substring(1); inputFields[FIELD_PHONECODE].setText(number.substring(0, 1)); } } if (textToSet != null) { inputFields[FIELD_PHONE].setText(textToSet); inputFields[FIELD_PHONE].setSelection(inputFields[FIELD_PHONE].length()); } } } } } catch (Exception e) { FileLog.e(e); } }
Example 18
Source Project: Telegram File: CancelAccountDeletionActivity.java License: GNU General Public License v2.0 | 4 votes |
@Override public void onNextPressed() { if (getParentActivity() == null || nextPressed) { return; } TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE; boolean allowCall = true; if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) { //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; /*if (checkPermissions) { permissionsItems.clear(); if (!allowCall) { permissionsItems.add(Manifest.permission.READ_PHONE_STATE); } if (!permissionsItems.isEmpty()) { SharedPreferences preferences = MessagesController.getGlobalMainSettings(); if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE)) { preferences.edit().putBoolean("firstlogin", false).commit(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall)); permissionsDialog = showDialog(builder.create()); } else { getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6); } return; } }*/ } final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode(); req.hash = hash; req.settings = new TLRPC.TL_codeSettings(); req.settings.allow_flashcall = false;//simcardAvailable && allowCall; req.settings.allow_app_hash = ApplicationLoader.hasPlayServices; SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); if (req.settings.allow_app_hash) { preferences.edit().putString("sms_hash", BuildVars.SMS_HASH).commit(); } else { preferences.edit().remove("sms_hash").commit(); } if (req.settings.allow_flashcall) { try { @SuppressLint("HardwareIds") String number = tm.getLine1Number(); if (!TextUtils.isEmpty(number)) { req.settings.current_number = PhoneNumberUtils.compare(phone, number); if (!req.settings.current_number) { req.settings.allow_flashcall = false; } } else { req.settings.current_number = false; } } catch (Exception e) { req.settings.allow_flashcall = false; FileLog.e(e); } } final Bundle params = new Bundle(); params.putString("phone", phone); nextPressed = true; ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { nextPressed = false; if (error == null) { fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response); } else { errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req); } }), ConnectionsManager.RequestFlagFailOnServerErrors); }
Example 19
Source Project: Telegram File: PaymentFormActivity.java License: GNU General Public License v2.0 | 4 votes |
@SuppressLint("HardwareIds") public void fillNumber(String number) { try { TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE); boolean allowCall = true; boolean allowSms = true; if (number != null || tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) { if (Build.VERSION.SDK_INT >= 23) { allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED; } if (number != null || allowCall) { if (number == null) { number = PhoneFormat.stripExceptNumbers(tm.getLine1Number()); } String textToSet = null; boolean ok = false; if (!TextUtils.isEmpty(number)) { if (number.length() > 4) { for (int a = 4; a >= 1; a--) { String sub = number.substring(0, a); String country = codesMap.get(sub); if (country != null) { ok = true; textToSet = number.substring(a); inputFields[FIELD_PHONECODE].setText(sub); break; } } if (!ok) { textToSet = number.substring(1); inputFields[FIELD_PHONECODE].setText(number.substring(0, 1)); } } if (textToSet != null) { inputFields[FIELD_PHONE].setText(textToSet); inputFields[FIELD_PHONE].setSelection(inputFields[FIELD_PHONE].length()); } } } } } catch (Exception e) { FileLog.e(e); } }
Example 20
Source Project: BigApp_Discuz_Android File: Tools.java License: Apache License 2.0 | 2 votes |
/** * 判断是否有sim卡 * @param context * @return */ public static boolean hasSimCard(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return telephonyManager != null && (telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT); }