Java Code Examples for android.telephony.TelephonyManager#getDeviceId()
The following examples show how to use
android.telephony.TelephonyManager#getDeviceId() .
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: VideoOS-Android-SDK File: VenvyDeviceUtil.java License: GNU General Public License v3.0 | 6 votes |
/** * 获取手机IMEI号,需要<uses-permission * android:name="android.permission.READ_PHONE_STATE" /> * * @param context * @return */ public static String getIMEI(final Context context) { String IMEI = ""; if (context == null) { return IMEI; } TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); if (PermissionCheckHelper.isPermissionGranted(context, Manifest.permission.READ_PHONE_STATE)) { IMEI = telephonyManager.getDeviceId(); if(TextUtils.isEmpty(IMEI)){ // 部分Android 版本下获取的DeviceId为null的解决方案 IMEI = Settings.Secure.getString(context.getApplicationContext().getContentResolver(),Settings.Secure.ANDROID_ID); } } else { IMEI = "000000000000000"; } return IMEI; }
Example 2
Source Project: MiBandDecompiled File: ai.java License: Apache License 2.0 | 6 votes |
protected final String g() { if (f == null && a != null) { b = (TelephonyManager)a.getSystemService("phone"); if (b != null) { f = b.getDeviceId(); } } if (f != null) { return f; } else { return ""; } }
Example 3
Source Project: ans-android-sdk File: CommonUtils.java License: GNU General Public License v3.0 | 5 votes |
/** * 获取 IMEI */ public static String getIMEI(Context context) { try { if (checkPermission(context, Manifest.permission.READ_PHONE_STATE)) { TelephonyManager telephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyMgr != null) { return telephonyMgr.getDeviceId(); } } } catch (Throwable ignore) { ExceptionUtil.exceptionThrow(ignore); } return Constants.EMPTY; }
Example 4
Source Project: android-common File: TelephoneUtil.java License: Apache License 2.0 | 5 votes |
/** * MTK Phone. * * 获取 MTK 神机的双卡 IMSI、IMSI 信息 */ public static TeleInfo getMtkTeleInfo2(Context context) { TeleInfo teleInfo = new TeleInfo(); try { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Class<?> phone = Class.forName("com.android.internal.telephony.Phone"); Field fields1 = phone.getField("GEMINI_SIM_1"); fields1.setAccessible(true); int simId_1 = (Integer) fields1.get(null); Field fields2 = phone.getField("GEMINI_SIM_2"); fields2.setAccessible(true); int simId_2 = (Integer) fields2.get(null); Method getDefault = TelephonyManager.class.getMethod("getDefault", int.class); TelephonyManager tm1 = (TelephonyManager) getDefault.invoke(tm, simId_1); TelephonyManager tm2 = (TelephonyManager) getDefault.invoke(tm, simId_2); String imsi_1 = tm1.getSubscriberId(); String imsi_2 = tm2.getSubscriberId(); teleInfo.imsi_1 = imsi_1; teleInfo.imsi_2 = imsi_2; String imei_1 = tm1.getDeviceId(); String imei_2 = tm2.getDeviceId(); teleInfo.imei_1 = imei_1; teleInfo.imei_2 = imei_2; int phoneType_1 = tm1.getPhoneType(); int phoneType_2 = tm2.getPhoneType(); teleInfo.phoneType_1 = phoneType_1; teleInfo.phoneType_2 = phoneType_2; } catch (Exception e) { e.printStackTrace(); } Log.i(TAG, "MTK2: " + teleInfo); return teleInfo; }
Example 5
Source Project: HaiNaBaiChuan File: ExampleUtil.java License: Apache License 2.0 | 5 votes |
public static String getImei(Context context, String imei) { try { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); imei = telephonyManager.getDeviceId(); } catch (Exception e) { Log.e(ExampleUtil.class.getSimpleName(), e.getMessage()); } return imei; }
Example 6
Source Project: android-performance File: GetDeviceIdTask.java License: MIT License | 5 votes |
@Override public void run() { // 真正自己的代码 TelephonyManager tManager = (TelephonyManager) mContext.getSystemService( Context.TELEPHONY_SERVICE); mDeviceId = tManager.getDeviceId(); PerformanceApp app = (PerformanceApp) mContext; app.setDeviceId(mDeviceId); }
Example 7
Source Project: ViewDebugHelper File: AppUtil.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * get the current version of current application */ public static String getImei( Context context) { if (TextUtils.isEmpty(imei)) { if(context.checkCallingOrSelfPermission( Manifest.permission.READ_PHONE_STATE)== PackageManager.PERMISSION_GRANTED){ TelephonyManager tm = (TelephonyManager) context.getApplicationContext() .getSystemService(Context.TELEPHONY_SERVICE); imei = tm.getDeviceId(); } } return imei; }
Example 8
Source Project: AndroidWallet File: Utils.java License: GNU General Public License v3.0 | 5 votes |
@SuppressLint("MissingPermission") public static String getImei(Context context) { String imei = ""; try { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); imei = telephonyManager.getDeviceId(); } catch (Exception e) { e.printStackTrace(); } return imei; }
Example 9
Source Project: AndroidHttpCapture File: SystemBasicInfo.java License: MIT License | 5 votes |
public static String getDeviceId(Context context) { try { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return tm.getDeviceId(); } catch (Exception e) { return "null"; } }
Example 10
Source Project: letv File: e.java License: Apache License 2.0 | 5 votes |
public String f() { TelephonyManager telephonyManager = (TelephonyManager) this.b.getSystemService("phone"); if (telephonyManager == null) { } try { if (bt.a(this.b, "android.permission.READ_PHONE_STATE")) { return telephonyManager.getDeviceId(); } return null; } catch (Exception e) { return null; } }
Example 11
Source Project: mpush-android File: MainActivity.java License: Apache License 2.0 | 5 votes |
private String getDeviceId() { TelephonyManager tm = (TelephonyManager) this.getSystemService(Activity.TELEPHONY_SERVICE); String deviceId = tm.getDeviceId(); if (TextUtils.isEmpty(deviceId)) { String time = Long.toString((System.currentTimeMillis() / (1000 * 60 * 60))); deviceId = time + time; } return deviceId; }
Example 12
Source Project: talk-android File: DeviceUtil.java License: MIT License | 5 votes |
public static String getDeviceId(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String deviceId = ""; try { deviceId = tm.getDeviceId(); } catch (Exception e) { e.printStackTrace(); } String macAddress = getMacAddress(); return deviceId + "-" + macAddress; }
Example 13
Source Project: letv File: Device.java License: Apache License 2.0 | 5 votes |
private static String getSystemDeviceID(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService("phone"); if (tm != null) { return tm.getDeviceId(); } FLOG.e(TAG, "get telephony service failed while getting deviceId"); return null; }
Example 14
Source Project: AndroidStudyDemo File: ImsiUtil.java License: GNU General Public License v2.0 | 5 votes |
/** * 展讯芯片的判断 * @return */ public IMSInfo initSpreadDoubleSim() { IMSInfo imsInfo = null; try { Class<?> c = Class .forName("com.android.internal.telephony.PhoneFactory"); Method m = c.getMethod("getServiceName", String.class, int.class); String spreadTmService = (String) m.invoke(c, Context.TELEPHONY_SERVICE, 1); TelephonyManager tm = (TelephonyManager) mContext .getSystemService(Context.TELEPHONY_SERVICE); imsi_1 = tm.getSubscriberId(); imei_1 = tm.getDeviceId(); TelephonyManager tm1 = (TelephonyManager) mContext .getSystemService(spreadTmService); imsi_2 = tm1.getSubscriberId(); imei_2 = tm1.getDeviceId(); imsInfo = new IMSInfo(); imsInfo.chipName = "展讯芯片"; imsInfo.imei_1 = imei_1; imsInfo.imei_2 = imei_2; imsInfo.imsi_1 = imsi_1; imsInfo.imsi_2 = imsi_2; } catch (Exception e) { imsInfo = null; return imsInfo; } return imsInfo; }
Example 15
Source Project: Beats File: DatapointHelper.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Gets the device's telephony ID (e.g. IMEI/MEID). * <p> * Note: this method will return null if {@link permission#READ_PHONE_STATE} is not available. This method will also return * null on devices that do not have telephony. * * @param context The context used to access the phone state. * @return An the {@link TelephonyManager#getDeviceId()}. Null if an ID is not available, or if * {@link permission#READ_PHONE_STATE} is not available. */ public static String getTelephonyDeviceIdOrNull(final Context context) { if (Constants.CURRENT_API_LEVEL >= 7) { final Boolean hasTelephony = ReflectionUtils.tryInvokeInstance(context.getPackageManager(), "hasSystemFeature", STRING_CLASS_ARRAY, HARDWARE_TELEPHONY); //$NON-NLS-1$ if (!hasTelephony.booleanValue()) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Device does not have telephony; cannot read telephony id"); //$NON-NLS-1$ } return null; } } /* * Note: Sometimes Android will deny a package READ_PHONE_STATE permissions, even if the package has the permission. It * appears to be a race condition that occurs during installation. */ String id = null; if (context.getPackageManager().checkPermission(permission.READ_PHONE_STATE, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) { final TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); id = manager.getDeviceId(); } else { if (Constants.IS_LOGGABLE) { Log.w(Constants.LOG_TAG, "Application does not have permission READ_PHONE_STATE; determining device id is not possible. Please consider requesting READ_PHONE_STATE in the AndroidManifest"); //$NON-NLS-1$ } } return id; }
Example 16
Source Project: PhoneMonitor File: HelperMethods.java License: GNU General Public License v3.0 | 5 votes |
static String getIMEI(Context context) { String retval = ""; TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { retval = telephonyManager.getDeviceId(); } return retval; }
Example 17
Source Project: AndroidBase File: TelephoneUtil.java License: Apache License 2.0 | 5 votes |
/** * MTK Phone. * <p> * 获取 MTK 神机的双卡 IMSI、IMSI 信息 */ public static TeleInfo getMtkTeleInfo2(Context context) { try { TeleInfo teleInfo = new TeleInfo(); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Class<?> phone = Class.forName("com.android.internal.telephony.Phone"); Field fields1 = phone.getField("GEMINI_SIM_1"); fields1.setAccessible(true); int simId_1 = (Integer) fields1.get(null); Field fields2 = phone.getField("GEMINI_SIM_2"); fields2.setAccessible(true); int simId_2 = (Integer) fields2.get(null); Method getDefault = TelephonyManager.class.getMethod("getDefault", int.class); TelephonyManager tm1 = (TelephonyManager) getDefault.invoke(tm, simId_1); TelephonyManager tm2 = (TelephonyManager) getDefault.invoke(tm, simId_2); String imsi_1 = tm1.getSubscriberId(); String imsi_2 = tm2.getSubscriberId(); teleInfo.imsi_1 = imsi_1; teleInfo.imsi_2 = imsi_2; String imei_1 = tm1.getDeviceId(); String imei_2 = tm2.getDeviceId(); teleInfo.imei_1 = imei_1; teleInfo.imei_2 = imei_2; int phoneType_1 = tm1.getPhoneType(); int phoneType_2 = tm2.getPhoneType(); teleInfo.phoneType_1 = phoneType_1; teleInfo.phoneType_2 = phoneType_2; LogUtils.i("MTK2: " + teleInfo); return teleInfo; } catch (Exception e) { e.printStackTrace(); return null; } }
Example 18
Source Project: Ticket-Analysis File: PhoneUtils.java License: MIT License | 4 votes |
/** * 获取手机状态信息 * <p>需添加权限<uses-permission android:name="android.permission.READ_PHONE_STATE"/> * <p>返回如下 * <pre> * DeviceId(IMEI) = 99000311726612 * DeviceSoftwareVersion = 00 * Line1Number = * NetworkCountryIso = cn * NetworkOperator = 46003 * NetworkOperatorName = 中国电信 * NetworkType = 6 * honeType = 2 * SimCountryIso = cn * SimOperator = 46003 * SimOperatorName = 中国电信 * SimSerialNumber = 89860315045710604022 * SimState = 5 * SubscriberId(IMSI) = 460030419724900 * VoiceMailNumber = *86 * <pre/> */ public static String getPhoneStatus(Context context) { TelephonyManager tm = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); String str = ""; str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n"; str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n"; str += "Line1Number = " + tm.getLine1Number() + "\n"; str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n"; str += "NetworkOperator = " + tm.getNetworkOperator() + "\n"; str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n"; str += "NetworkType = " + tm.getNetworkType() + "\n"; str += "honeType = " + tm.getPhoneType() + "\n"; str += "SimCountryIso = " + tm.getSimCountryIso() + "\n"; str += "SimOperator = " + tm.getSimOperator() + "\n"; str += "SimOperatorName = " + tm.getSimOperatorName() + "\n"; str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n"; str += "SimState = " + tm.getSimState() + "\n"; str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n"; str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n"; return str; }
Example 19
Source Project: mobile-manager-tool File: SystemUtils.java License: MIT License | 4 votes |
public static String getDeviceId() { TelephonyManager tm = (TelephonyManager) AppMain.getInstance().getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); return tm.getDeviceId(); }
Example 20
Source Project: Android-UtilCode File: PhoneUtils.java License: Apache License 2.0 | 2 votes |
/** * 获取IMEI码 * <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p> * * @return IMEI码 */ @SuppressLint("HardwareIds") public static String getIMEI() { TelephonyManager tm = (TelephonyManager) Utils.getContext().getSystemService(Context.TELEPHONY_SERVICE); return tm != null ? tm.getDeviceId() : null; }