List of usage examples for android.telephony TelephonyManager getDeviceId
@Deprecated
@SuppressAutoDoc
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getDeviceId()
From source file:com.simadanesh.isatis.LoginActivity.java
private String getIMEI() { _IMEI = "000000000000000"; try {//from ww w . j a v a 2s .c om int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE); if (rc != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_PHONE_STATE, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA, Manifest.permission.WAKE_LOCK, Manifest.permission.INTERNET, Manifest.permission.FLASHLIGHT }, REQUEST_READ_PHONE_STATE); } TelephonyManager telman = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); _IMEI = telman.getDeviceId(); } catch (Exception ex) { Toast.makeText(this, "permission denied.", Toast.LENGTH_SHORT).show(); _IMEI = "000000000000000"; } //_IMEI = "355177060657084"; return _IMEI; }
From source file:com.framgia.android.emulator.EmulatorDetector.java
private boolean checkDeviceId() { TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); @SuppressLint("HardwareIds") String deviceId = telephonyManager.getDeviceId(); for (String known_deviceId : DEVICE_IDS) { if (known_deviceId.equalsIgnoreCase(deviceId)) { log("Check device id is detected"); return true; }/*from ww w.j a va2 s.co m*/ } return false; }
From source file:com.techies11.FbLoginActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //this.getActionBar().hide(); // FacebookSdk.sdkInitialize(getApplicationContext()); setContentView(R.layout.fblogin);//from ww w .j a va 2s . co m MultiDex.install(this); //HttpGet httpGet = new HttpGet(http://192.168.1.12?) ; // Configure sign-in to request the user's ID, email address, and basic // profile. ID and basic profile are included in DEFAULT_SIGN_IN. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail().build(); // Build a GoogleApiClient with access to the Google Sign-In API and the // options specified by gso. mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build(); SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button); signInButton.setSize(SignInButton.SIZE_STANDARD); signInButton.setScopes(gso.getScopeArray()); signInButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); startActivityForResult(signInIntent, RC_SIGN_IN); } }); // callbackManager = CallbackManager.Factory.create(); // accessTokenTracker= new AccessTokenTracker() { // @Override // protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) { // // } // }; // profileTracker = new ProfileTracker() { // @Override // protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) { // displayMessage(newProfile); // } // }; // // accessTokenTracker.startTracking(); // profileTracker.startTracking(); // // loginButton = (LoginButton) findViewById(R.id.login_button); // loginButton.setReadPermissions("user_friends"); // // loginButton.registerCallback(callbackManager, callback); // //LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile","email", "user_friends")); TelephonyManager telephonyManager = (TelephonyManager) getSystemService( getApplicationContext().TELEPHONY_SERVICE); deviceid = telephonyManager.getDeviceId(); settings = getSharedPreferences(ConstValue.MAIN_PREF, 0); cd = new ConnectionDetector(this); btnLogin = (Button) findViewById(R.id.buttonLogin); btnRegister = (Button) findViewById(R.id.buttonRegister); btnLogin.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(FbLoginActivity.this, Login2Activity.class); startActivity(intent); } }); btnRegister.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(FbLoginActivity.this, RegisterActivity.class); startActivity(intent); } }); Button continuebtn = (Button) findViewById(R.id.button1); continuebtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(FbLoginActivity.this, MainActivity.class); startActivity(intent); finish(); } }); }
From source file:de.ub0r.android.otpdroid.OTPdroid.java
/** * Load IMEI and SIMID from phone./*from w w w. jav a 2s . c o m*/ */ private void loadKeys() { TelephonyManager phone = (TelephonyManager) this.getApplicationContext() .getSystemService(Context.TELEPHONY_SERVICE); this.imei = phone.getDeviceId(); this.simid = phone.getSimSerialNumber(); }
From source file:com.gmobi.poponews.util.HttpHelper.java
public JSONObject getDeviceInfo() { ;/* w ww . ja v a2 s.c o m*/ TelephonyManager mTelephonyMgr = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); String imsi = mTelephonyMgr.getSubscriberId(); String imei = mTelephonyMgr.getDeviceId(); JSONObject json = new JSONObject(); try { json.put("app", mContext.getPackageName()); json.put("ch", PreferenceHelper.getCurChannel(mContext)); json.put("group", BuildConfig.GROUP); json.put("app_v", SystemHelper.getAppVersion(mContext)); json.put("imsi", imsi); json.put("imei", imei); json.put("sd", SystemHelper.hasSdcard(mContext)); json.put("ua", SystemHelper.getUA(false)); json.put("os", "android"); json.put("os_v", SystemHelper.getOsVersion()); json.put("lang", Locale.getDefault().getLanguage()); json.put("country", SystemHelper.getCountry(mContext)); json.put("wmac", SystemHelper.getWifiMac(mContext)); json.put("bmac", ""); json.put("sn", SystemHelper.getAndroidId(mContext)); json.put("sa", SystemHelper.isSystemApp(mContext)); json.put("sw", SystemHelper.getScreenWidth(mContext)); json.put("sh", SystemHelper.getScreenHeight(mContext)); json.put("dch", BuildConfig.DISTRIBUTION_CHANNEL); json.put("gref", new JSONObject("{}")); Logger.debug("Send Device Info: " + json.toString(4)); } catch (JSONException e) { Logger.error(e); } return json; }
From source file:io.rapidpro.androidchannel.RapidPro.java
/** * Generates a UUID that should be constant across devices. This uses a combination of the IMEI if available * and the AndroidId. Note that both of these could be empty but it is very unlikely both are. * * @return/* www. j a v a 2 s. co m*/ */ public String generateUUID() { final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE); final String tmDevice, androidId; tmDevice = "" + tm.getDeviceId(); androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); UUID deviceUUID = new UUID(androidId.hashCode(), tmDevice.hashCode()); return deviceUUID.toString(); }
From source file:com.wbtech.ums.UmsAgent.java
private static JSONObject getClientDataJSONObject(Context context) { TelephonyManager tm = (TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE)); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displaysMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(displaysMetrics); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); JSONObject clientData = new JSONObject(); try {//from www . j a v a 2s . c om clientData.put("os_version", CommonUtil.getOsVersion(context)); clientData.put("platform", "android"); clientData.put("language", Locale.getDefault().getLanguage()); clientData.put("deviceid", tm.getDeviceId() == null ? "" : tm.getDeviceId());// clientData.put("appkey", CommonUtil.getAppKey(context)); clientData.put("resolution", displaysMetrics.widthPixels + "x" + displaysMetrics.heightPixels); clientData.put("ismobiledevice", true); clientData.put("phonetype", tm.getPhoneType());// clientData.put("imsi", tm.getSubscriberId()); clientData.put("network", CommonUtil.getNetworkTypeWIFI2G3G(context)); clientData.put("time", CommonUtil.getTime()); clientData.put("version", CommonUtil.getVersion(context)); clientData.put(UserIdentifier, CommonUtil.getUserIdentifier(context)); SCell sCell = CommonUtil.getCellInfo(context); clientData.put("mccmnc", sCell != null ? "" + sCell.MCCMNC : ""); clientData.put("cellid", sCell != null ? sCell.CID + "" : ""); clientData.put("lac", sCell != null ? sCell.LAC + "" : ""); clientData.put("modulename", Build.PRODUCT); clientData.put("devicename", CommonUtil.getDeviceName()); clientData.put("wifimac", wifiManager.getConnectionInfo().getMacAddress()); clientData.put("havebt", adapter == null ? false : true); clientData.put("havewifi", CommonUtil.isWiFiActive(context)); clientData.put("havegps", locationManager == null ? false : true); clientData.put("havegravity", CommonUtil.isHaveGravity(context));// LatitudeAndLongitude coordinates = CommonUtil.getLatitudeAndLongitude(context, UmsAgent.mUseLocationService); clientData.put("latitude", coordinates.latitude); clientData.put("longitude", coordinates.longitude); CommonUtil.printLog("clientData---------->", clientData.toString()); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return clientData; }
From source file:org.hfoss.posit.web.Communicator.java
public Communicator(Context _context) { mContext = _context;/*w w w . j a v a 2 s .co m*/ mTotalTime = 0; mStart = 0; mHttpParams = new BasicHttpParams(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); mConnectionManager = new ThreadSafeClientConnManager(mHttpParams, registry); mHttpClient = new DefaultHttpClient(mConnectionManager, mHttpParams); PreferenceManager.setDefaultValues(mContext, R.xml.posit_preferences, false); applicationPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); setApplicationAttributes(applicationPreferences.getString("AUTHKEY", ""), applicationPreferences.getString("SERVER_ADDRESS", server), applicationPreferences.getInt("PROJECT_ID", projectId)); TelephonyManager manager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); imei = manager.getDeviceId(); }
From source file:xj.property.ums.UmsAgent.java
public static JSONObject getClientDataJSONObject(Context context) { TelephonyManager tm = (TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE)); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displaysMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(displaysMetrics); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); JSONObject clientData = new JSONObject(); try {// ww w .ja v a 2 s . c om clientData.put("os_version", CommonUtil.getOsVersion(context)); clientData.put("platform", "android"); clientData.put("language", Locale.getDefault().getLanguage()); clientData.put("deviceid", tm.getDeviceId() == null ? "" : tm.getDeviceId());// clientData.put("appkey", CommonUtil.getAppKey(context)); clientData.put("resolution", displaysMetrics.widthPixels + "x" + displaysMetrics.heightPixels); clientData.put("ismobiledevice", true); clientData.put("phonetype", tm.getPhoneType());// clientData.put("imsi", tm.getSubscriberId()); clientData.put("network", CommonUtil.getNetworkTypeWIFI2G3G(context)); clientData.put("time", CommonUtil.getTime()); clientData.put("version", CommonUtil.getVersion(context)); clientData.put(UserIdentifier, CommonUtil.getUserIdentifier(context)); SCell sCell = CommonUtil.getCellInfo(context); clientData.put("mccmnc", sCell != null ? "" + sCell.MCCMNC : ""); clientData.put("cellid", sCell != null ? sCell.CID + "" : ""); clientData.put("lac", sCell != null ? sCell.LAC + "" : ""); clientData.put("modulename", Build.PRODUCT); clientData.put("devicename", CommonUtil.getDeviceName()); clientData.put("wifimac", wifiManager.getConnectionInfo().getMacAddress()); clientData.put("havebt", adapter == null ? false : true); clientData.put("havewifi", CommonUtil.isWiFiActive(context)); clientData.put("havegps", locationManager == null ? false : true); clientData.put("havegravity", CommonUtil.isHaveGravity(context));// LatitudeAndLongitude coordinates = CommonUtil.getLatitudeAndLongitude(context, UmsAgent.mUseLocationService); clientData.put("latitude", coordinates.latitude); clientData.put("longitude", coordinates.longitude); CommonUtil.printLog("clientData---------->", clientData.toString()); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return clientData; }
From source file:com.example.jumpnote.android.SyncAdapter.java
@Override public void onPerformSync(final Account account, Bundle extras, String authority, final ContentProviderClient provider, final SyncResult syncResult) { TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); String clientDeviceId = tm.getDeviceId(); final long newSyncTime = System.currentTimeMillis(); final boolean uploadOnly = extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false); final boolean manualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false); final boolean initialize = extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, false); C2DMReceiver.refreshAppC2DMRegistrationState(mContext); Log.i(TAG, "Beginning " + (uploadOnly ? "upload-only" : "full") + " sync for account " + account.name); // Read this account's sync metadata final SharedPreferences syncMeta = mContext.getSharedPreferences("sync:" + account.name, 0); long lastSyncTime = syncMeta.getLong(LAST_SYNC, 0); long lastServerSyncTime = syncMeta.getLong(SERVER_LAST_SYNC, 0); // Check for changes in either app-wide auto sync registration information, or changes in // the user's preferences for auto sync on this account; if either changes, piggy back the // new registration information in this sync. long lastRegistrationChangeTime = C2DMessaging.getLastRegistrationChange(mContext); boolean autoSyncDesired = ContentResolver.getMasterSyncAutomatically() && ContentResolver.getSyncAutomatically(account, JumpNoteContract.AUTHORITY); boolean autoSyncEnabled = syncMeta.getBoolean(DM_REGISTERED, false); // Will be 0 for no change, -1 for unregister, 1 for register. final int deviceRegChange; JsonRpcClient.Call deviceRegCall = null; if (autoSyncDesired != autoSyncEnabled || lastRegistrationChangeTime > lastSyncTime || initialize || manualSync) {// w w w . j a va 2 s . co m String registrationId = C2DMessaging.getRegistrationId(mContext); deviceRegChange = (autoSyncDesired && registrationId != null) ? 1 : -1; if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Auto sync selection or registration information has changed, " + (deviceRegChange == 1 ? "registering" : "unregistering") + " messaging for this device, for account " + account.name); } try { if (deviceRegChange == 1) { // Register device for auto sync on this account. deviceRegCall = new JsonRpcClient.Call(JumpNoteProtocol.DevicesRegister.METHOD); JSONObject params = new JSONObject(); DeviceRegistration device = new DeviceRegistration(clientDeviceId, DEVICE_TYPE, registrationId); params.put(JumpNoteProtocol.DevicesRegister.ARG_DEVICE, device.toJSON()); deviceRegCall.setParams(params); } else { // Unregister device for auto sync on this account. deviceRegCall = new JsonRpcClient.Call(JumpNoteProtocol.DevicesUnregister.METHOD); JSONObject params = new JSONObject(); params.put(JumpNoteProtocol.DevicesUnregister.ARG_DEVICE_ID, clientDeviceId); deviceRegCall.setParams(params); } } catch (JSONException e) { logErrorMessage("Error generating device registration remote RPC parameters.", manualSync); e.printStackTrace(); return; } } else { deviceRegChange = 0; } // Get the list of locally changed notes. If this is an upload-only sync and there were // no local changes, cancel the sync. List<ModelJava.Note> locallyChangedNotes = null; try { locallyChangedNotes = getLocallyChangedNotes(provider, account, new Date(lastSyncTime)); } catch (RemoteException e) { logErrorMessage("Remote exception accessing content provider: " + e.getMessage(), manualSync); e.printStackTrace(); syncResult.stats.numIoExceptions++; return; } if (uploadOnly && locallyChangedNotes.isEmpty() && deviceRegCall == null) { Log.i(TAG, "No local changes; upload-only sync canceled."); return; } // Set up the RPC sync calls final AuthenticatedJsonRpcJavaClient jsonRpcClient = new AuthenticatedJsonRpcJavaClient(mContext, Config.SERVER_AUTH_URL_TEMPLATE, Config.SERVER_RPC_URL); try { jsonRpcClient.blockingAuthenticateAccount(account, manualSync ? AuthenticatedJsonRpcJavaClient.NEED_AUTH_INTENT : AuthenticatedJsonRpcJavaClient.NEED_AUTH_NOTIFICATION, false); } catch (AuthenticationException e) { logErrorMessage("Authentication exception when attempting to sync.", manualSync); e.printStackTrace(); syncResult.stats.numAuthExceptions++; return; } catch (OperationCanceledException e) { Log.i(TAG, "Sync for account " + account.name + " manually canceled."); return; } catch (RequestedUserAuthenticationException e) { syncResult.stats.numAuthExceptions++; return; } catch (InvalidAuthTokenException e) { logErrorMessage("Invalid auth token provided by AccountManager when attempting to " + "sync.", manualSync); e.printStackTrace(); syncResult.stats.numAuthExceptions++; return; } // Set up the notes sync call. JsonRpcClient.Call notesSyncCall = new JsonRpcClient.Call(JumpNoteProtocol.NotesSync.METHOD); try { JSONObject params = new JSONObject(); params.put(JumpNoteProtocol.ARG_CLIENT_DEVICE_ID, clientDeviceId); params.put(JumpNoteProtocol.NotesSync.ARG_SINCE_DATE, Util.formatDateISO8601(new Date(lastServerSyncTime))); JSONArray locallyChangedNotesJson = new JSONArray(); for (ModelJava.Note locallyChangedNote : locallyChangedNotes) { locallyChangedNotesJson.put(locallyChangedNote.toJSON()); } params.put(JumpNoteProtocol.NotesSync.ARG_LOCAL_NOTES, locallyChangedNotesJson); notesSyncCall.setParams(params); } catch (JSONException e) { logErrorMessage("Error generating sync remote RPC parameters.", manualSync); e.printStackTrace(); syncResult.stats.numParseExceptions++; return; } List<JsonRpcClient.Call> jsonRpcCalls = new ArrayList<JsonRpcClient.Call>(); jsonRpcCalls.add(notesSyncCall); if (deviceRegChange != 0) jsonRpcCalls.add(deviceRegCall); jsonRpcClient.callBatch(jsonRpcCalls, new JsonRpcClient.BatchCallback() { public void onData(Object[] data) { if (data[0] != null) { // Read notes sync data. JSONObject dataJson = (JSONObject) data[0]; try { List<ModelJava.Note> changedNotes = new ArrayList<ModelJava.Note>(); JSONArray notesJson = dataJson.getJSONArray(JumpNoteProtocol.NotesSync.RET_NOTES); for (int i = 0; i < notesJson.length(); i++) { changedNotes.add(new ModelJava.Note(notesJson.getJSONObject(i))); } reconcileSyncedNotes(provider, account, changedNotes, syncResult.stats); // If sync is successful (no exceptions thrown), update sync metadata long newServerSyncTime = Util .parseDateISO8601(dataJson.getString(JumpNoteProtocol.NotesSync.RET_NEW_SINCE_DATE)) .getTime(); syncMeta.edit().putLong(LAST_SYNC, newSyncTime).commit(); syncMeta.edit().putLong(SERVER_LAST_SYNC, newServerSyncTime).commit(); Log.i(TAG, "Sync complete, setting last sync time to " + Long.toString(newSyncTime)); } catch (JSONException e) { logErrorMessage("Error parsing note sync RPC response", manualSync); e.printStackTrace(); syncResult.stats.numParseExceptions++; return; } catch (ParseException e) { logErrorMessage("Error parsing note sync RPC response", manualSync); e.printStackTrace(); syncResult.stats.numParseExceptions++; return; } catch (RemoteException e) { logErrorMessage("RemoteException in reconcileSyncedNotes: " + e.getMessage(), manualSync); e.printStackTrace(); return; } catch (OperationApplicationException e) { logErrorMessage("Could not apply batch operations to content provider: " + e.getMessage(), manualSync); e.printStackTrace(); return; } finally { provider.release(); } } // Read device reg data. if (deviceRegChange != 0) { // data[1] will be null in case of an error (successful unregisters // will have an empty JSONObject, not null). boolean registered = (data[1] != null && deviceRegChange == 1); syncMeta.edit().putBoolean(DM_REGISTERED, registered).commit(); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Stored account auto sync registration state: " + Boolean.toString(registered)); } } } public void onError(int callIndex, JsonRpcException e) { if (e.getHttpCode() == 403) { Log.w(TAG, "Got a 403 response, invalidating App Engine ACSID token"); jsonRpcClient.invalidateAccountAcsidToken(account); } provider.release(); logErrorMessage("Error calling remote note sync RPC", manualSync); e.printStackTrace(); } }); }