List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
/** * Handles pre V19 uri's/*from ww w . ja va 2 s . com*/ * @param context * @param contentUri * @return */ private static String getPathForPreV19(Context context, Uri contentUri) { String res = null; String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); res = cursor.getString(column_index); } cursor.close(); } return res; }
From source file:Main.java
/** * get hashed unique id of the device//from ww w . j a va 2 s .co m * * @param context * @return * @throws UnsupportedEncodingException * @throws NoSuchAlgorithmException */ public static String getHashId(Context context) throws NoSuchAlgorithmException, UnsupportedEncodingException { String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); return SHA1(androidId); }
From source file:Main.java
public static void copyUri(Uri uri, Context context) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newUri(context.getContentResolver(), "uri", uri)); }
From source file:Main.java
public static ArrayList<String> findSmsByAddress(Context context, String address) { ArrayList<String> list = new ArrayList<String>(); try {/* w ww. j a va 2 s. co m*/ Cursor c = context.getContentResolver().query(Uri.parse("content://sms/inbox"), new String[] { "_id", "address" }, "address = ?", new String[] { address }, null); if (!c.moveToFirst() || c.getCount() == 0) { LOGI("there are no more messages"); c.close(); return list; } do { list.add(c.getString(0)); } while (c.moveToNext()); c.close(); } catch (Exception e) { LOGE("findSmsByAddress: " + e.getMessage()); } return list; }
From source file:Main.java
static String getFileName(Context context, Uri uri) { String result = null;//from w ww .j a va 2 s. com if (uri.getScheme().equals("content")) { Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); } } catch (Exception e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } } if (result == null) { result = uri.getPath(); int cut = result.lastIndexOf(File.separator); if (cut != -1) { result = result.substring(cut + 1); } } return result; }
From source file:Main.java
/** * Acquires input stream for the image resource identified by uri. * * This is a long-running I/O operation that must run in a background thread. * * @param context// w w w.ja v a 2 s.c o m * @param uri * @return * @throws IOException */ public static InputStream getInputStream(Context context, Uri uri) throws IOException { if (uri.getScheme().contentEquals(ContentResolver.SCHEME_CONTENT)) { return context.getContentResolver().openInputStream(uri); } else { return (InputStream) new URL(uri.toString()).getContent(); } }
From source file:Main.java
public static String FromCameraResult(Intent data, Context context, File file) { try {// w w w .j a va 2s. c o m if (file != null) { Uri u = Uri.parse(MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), null, null)); return getPathFromUri(context, u); } } catch (Exception e) { return null; } return null; }
From source file:Main.java
public static void insertImage(Context context, String absolutePath, String name) throws FileNotFoundException { // Check if file exists with a FileInputStream MediaStore.Images.Media.insertImage(context.getContentResolver(), absolutePath, name, null); }
From source file:Main.java
public static String getRecentCallsInfo(Context context) { StringBuilder stringBuilder = new StringBuilder(); Cursor cursor = context.getContentResolver().query(Calls.CONTENT_URI, null, null, null, Calls.DATE + " DESC"); int number = cursor.getColumnIndex(Calls.NUMBER); int name = cursor.getColumnIndex(Calls.CACHED_NAME); int type = cursor.getColumnIndex(Calls.TYPE); int date = cursor.getColumnIndex(Calls.DATE); int duration = cursor.getColumnIndex(Calls.DURATION); while (cursor.moveToNext()) { String phNumber = cursor.getString(number); String cachedName = cursor.getString(name); String callType = cursor.getString(type); String callDuration = cursor.getString(duration); String callDate = cursor.getString(date); Date callDayTime = new Date(Long.valueOf(callDate)); String dir;/*w w w . j a va 2 s .c om*/ int dircode = Integer.parseInt(callType); switch (dircode) { case Calls.OUTGOING_TYPE: dir = "OUTGOING"; break; case Calls.INCOMING_TYPE: dir = "INCOMING"; break; case Calls.MISSED_TYPE: dir = "MISSED"; break; default: dir = "UNKNOWN " + dircode; } stringBuilder.append("\nPhone Number:--- ").append(phNumber).append("\nPhone formatted:--- ") .append(PhoneNumberUtils.formatNumber(phNumber)).append("\nCached name:--- ").append(cachedName) .append("\nCall Type:--- ").append(dir).append("\nCall Date:--- ").append(callDayTime) .append("\nCall duration in sec :--- ").append(callDuration) .append("\n----------------------------------"); } cursor.close(); return stringBuilder.toString(); }
From source file:Main.java
public static Bitmap decodeUriAsBitmap(Context context, Uri uri, BitmapFactory.Options options) { Bitmap result = null;/*from w w w. ja va 2 s .c om*/ if (uri != null) { ContentResolver cr = context.getContentResolver(); InputStream inputStream = null; try { inputStream = cr.openInputStream(uri); result = BitmapFactory.decodeStream(inputStream, null, options); inputStream.close(); } catch (Exception e) { e.printStackTrace(); } } return result; }