List of usage examples for android.util Log e
public static int e(String tag, String msg, Throwable tr)
From source file:Main.java
public static <T> List<T> readList(String root, String filename, Class<T> type) { List<T> objects = new ArrayList<>(); File file = new File(root, filename); try {/*from w w w . j a va 2 s .c o m*/ if (file.exists()) { FileInputStream fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis); Object object = ois.readObject(); if (object instanceof List) { for (Object it : (List) object) { objects.add(type.cast(it)); } } ois.close(); return Collections.unmodifiableList(objects); } } catch (Exception e) { Log.e(TAG, String.format("Failed to read [%s]", file), e); } return Collections.emptyList(); }
From source file:Main.java
/** * see http://habrahabr.ru/post/144547///from w w w . j a v a 2s.c o m */ public static BluetoothSocket createRfcommSocket(BluetoothDevice device) { BluetoothSocket tmp = null; try { Class class1 = device.getClass(); Class aclass[] = new Class[1]; aclass[0] = Integer.TYPE; Method method = class1.getMethod("createRfcommSocket", aclass); Object aobj[] = new Object[1]; aobj[0] = Integer.valueOf(1); tmp = (BluetoothSocket) method.invoke(device, aobj); } catch (NoSuchMethodException e) { e.printStackTrace(); if (D) Log.e(TAG, "createRfcommSocket() failed", e); } catch (InvocationTargetException e) { e.printStackTrace(); if (D) Log.e(TAG, "createRfcommSocket() failed", e); } catch (IllegalAccessException e) { e.printStackTrace(); if (D) Log.e(TAG, "createRfcommSocket() failed", e); } return tmp; }
From source file:Main.java
/** * Copy database files to the given folder. Useful for debugging. * * @param folder the directory to copy files into *//*from ww w . j ava2 s. c o m*/ public static void copyDatabases(Context context, String folder) { File folderFile = new File(folder); if (!folderFile.exists()) { folderFile.mkdir(); } for (String db : context.databaseList()) { File dbFile = context.getDatabasePath(db); try { copyFile(dbFile, new File(folderFile.getAbsolutePath() + File.separator + db)); } catch (Exception e) { Log.e("ERROR", "ERROR COPYING DB " + db, e); } } }
From source file:Main.java
public static void setFieldValue(final Object receiver, final Field field, final Object value) { if (field == null) { return;//w ww . j a va2s.c o m } try { field.set(receiver, value); } catch (final IllegalAccessException | IllegalArgumentException e) { Log.e(TAG, "Exception in setFieldValue", e); } }
From source file:Main.java
public static BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException { UUID uuid = UUID.fromString(SERIAL_SERVICE_UUID); BluetoothSocket socket = null;//w w w . j a v a 2 s . c om if (Build.VERSION.SDK_INT >= 10) { try { final Method m = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class }); System.out.println("Performing invoke"); socket = (BluetoothSocket) m.invoke(device, uuid); System.out.println("Invoke done"); System.out.println(socket); } catch (Exception e) { Log.e("error", "Could not create Insecure RFComm Connection", e); } } else { //TODO, support older versions with secure connection } return socket; }
From source file:Main.java
public static Object getFieldValue(final Object receiver, final Object defaultValue, final Field field) { if (field == null) { return defaultValue; }// www . jav a 2s . c om try { return field.get(receiver); } catch (final IllegalAccessException | IllegalArgumentException e) { Log.e(TAG, "Exception in getFieldValue", e); } return defaultValue; }
From source file:Main.java
public static void saveBitmapToFile(Bitmap bitmap, String _file) throws IOException { BufferedOutputStream os = null; try {// w w w. j a va 2 s .c o m File file = new File(_file); // String _filePath_file.replace(File.separatorChar + // file.getName(), ""); int end = _file.lastIndexOf(File.separator); String _filePath = _file.substring(0, end); File filePath = new File(_filePath); if (!filePath.exists()) { filePath.mkdirs(); } file.createNewFile(); os = new BufferedOutputStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); } finally { if (os != null) { try { os.close(); } catch (IOException e) { Log.e("TAG_ERROR", e.getMessage(), e); } } } }
From source file:Main.java
/** * set the value to share config/* ww w.j a va 2 s . c o m*/ * @param context context * @param key key of the config * @param value value of the config */ public static void set(Context context, String key, String value) { ContentValues values = new ContentValues(); values.put("key", key); values.put("value", value); try { context.getContentResolver().insert(CONTENT_URI, values); } catch (IllegalArgumentException e1) { } catch (Exception e) { Log.e("AspShareUtil", "Error while set", e); } }
From source file:Main.java
public static boolean check(Context context, String... premissions) { try {/* www .j a va2s . co m*/ if (null == context) throw new RuntimeException("Context is null."); for (int i = 0; i < premissions.length; i++) { Integer check = context.checkPermission(premissions[i], Binder.getCallingPid(), Binder.getCallingUid()); if (check == -1) { return false; } } return true; } catch (Exception e) { Log.e(TAG, e.getMessage(), e); return false; } }
From source file:Main.java
@Nullable public static Camera getCameraInstance() { Camera c = null;// w w w .j a v a2s . c om try { c = Camera.open(); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } return c; }