List of usage examples for java.util UUID randomUUID
public static UUID randomUUID()
From source file:Main.java
public static String getDeviceId(Context context) { final String PREFS_DEVICE_ID = "prefs_device_id"; final String PREF_DEVICE_ID = "device_id"; SharedPreferences sp = context.getSharedPreferences(PREFS_DEVICE_ID, Context.MODE_PRIVATE); String deviceId = sp.getString(PREF_DEVICE_ID, null); if (deviceId == null) { deviceId = UUID.randomUUID().toString(); sp.edit().putString(PREF_DEVICE_ID, deviceId).apply(); }/*from w ww .jav a2 s . c o m*/ return deviceId; }
From source file:Main.java
public static boolean saveToSDCard(Bitmap bitmap) { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return false; }/*from w w w . ja v a 2s . co m*/ FileOutputStream fileOutputStream = null; File file = new File("/sdcard/myName/Download/"); if (!file.exists()) { file.mkdirs(); } String fileName = UUID.randomUUID().toString() + ".jpg"; String filePath = "/sdcard/myName/Download/" + fileName; File f = new File(filePath); if (!f.exists()) { try { f.createNewFile(); fileOutputStream = new FileOutputStream(filePath); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream); } catch (IOException e) { return false; } finally { try { fileOutputStream.flush(); fileOutputStream.close(); } catch (IOException e) { return false; } } } return true; }
From source file:Main.java
public static String getUUID() { return UUID.randomUUID().toString(); }
From source file:Main.java
public synchronized static String guid(Context context) { if (uniqueID == null) { SharedPreferences sharedPrefs = context.getSharedPreferences(PREF_UNIQUE_ID, Context.MODE_PRIVATE); uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null); if (uniqueID == null) { uniqueID = UUID.randomUUID().toString(); Editor editor = sharedPrefs.edit(); editor.putString(PREF_UNIQUE_ID, uniqueID); editor.commit();// w ww. ja va 2 s .co m } } return uniqueID; }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromUrl(String urlpath, long allowedBmpMaxMemorySize) { String tmpDir = System.getProperty("java.io.tmpdir", "."); File saveFile = new File(tmpDir, UUID.randomUUID().toString()); if (saveFile.exists()) { saveFile.delete();/*from w ww . j a v a 2s. c om*/ } try { saveFile.createNewFile(); File ret = downloadFile(urlpath, saveFile); if (ret == null) {// fail. return null; } Bitmap bmp = decodeSampledBitmapFromPath(saveFile.getAbsolutePath(), allowedBmpMaxMemorySize); return bmp; } catch (Throwable err) { err.printStackTrace(); } finally { if (saveFile.exists()) { saveFile.delete();// true. } } return null; }
From source file:Main.java
public static String upLoad(File file, String RequestURL) { String BOUNDER = UUID.randomUUID().toString(); String PREFIX = "--"; String END = "/r/n"; try {/*from w w w .j a v a 2 s.c o m*/ URL url = new URL(RequestURL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setReadTimeout(TIME_OUT); connection.setDoInput(true); connection.setDoOutput(true); connection.setUseCaches(false); connection.setRequestMethod("POST"); connection.setRequestProperty("Charset", CHARSET); connection.setRequestProperty("Connection", "Keep-Alive"); connection.setRequestProperty("Cotent-Type", CONTENT_TYPE + ";boundary=" + BOUNDER); if (file != null) { OutputStream outputStream = connection.getOutputStream(); DataOutputStream dataOutputStream = new DataOutputStream(outputStream); StringBuffer sb = new StringBuffer(); sb.append(PREFIX); sb.append(BOUNDER + END); dataOutputStream.write(sb.toString().getBytes()); InputStream in = new FileInputStream(file); byte[] b = new byte[1024]; int l = 0; while ((l = in.read()) != -1) { outputStream.write(b, 0, l); } in.close(); dataOutputStream.write(END.getBytes()); dataOutputStream.write((PREFIX + BOUNDER + PREFIX + END).getBytes()); dataOutputStream.flush(); int i = connection.getResponseCode(); if (i == 200) { return SUCCESS; } } } catch (IOException e) { e.printStackTrace(); } return FALIURE; }
From source file:Main.java
public static String createDeliveryId() { return UUID.randomUUID().toString().replace("-", "").substring(0, 3); }
From source file:Main.java
public static String genUUID() { return "uuid:" + UUID.randomUUID().toString(); }
From source file:Main.java
protected static String generateUniqueId() { return UUID.randomUUID().toString(); }
From source file:Main.java
protected static String generateRandomContainerName() { String containerName = "container" + UUID.randomUUID().toString(); return containerName.replace("-", ""); }