List of usage examples for android.net Uri toString
public abstract String toString();
From source file:Main.java
protected static Uri scaleDown(Uri imageUri, int targetSize, Context context) { System.gc();/* w ww .java2s .c om*/ String imagePath = getImagePath(imageUri, context); Bitmap currentImage = BitmapFactory.decodeFile(imagePath); int targetWidth = targetSize; int targetHeight = targetSize; int width = currentImage.getWidth(); int height = currentImage.getHeight(); if (width < targetWidth || height < targetHeight) { currentImage.recycle(); currentImage = null; System.gc(); return Uri.parse(imageUri.toString()); } height = (int) (height * (float) targetWidth / width); Bitmap scaledBitmap = Bitmap.createScaledBitmap(currentImage, targetWidth, height, false); if (currentImage != scaledBitmap) { currentImage.recycle(); currentImage = null; } System.gc(); File imageFile; try { imageFile = new File(context.getCacheDir(), "vumatch-upload-00.jpeg"); FileOutputStream output; output = new FileOutputStream(imageFile); boolean result = scaledBitmap.compress(CompressFormat.JPEG, 90, output); if (result) { scaledBitmap.recycle(); scaledBitmap = null; return Uri.fromFile(imageFile); } else { return null; } } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
From source file:com.cyberocw.habittodosecretary.file.StorageHelper.java
/** * Retrieves uri mime-type using ContentResolver * * @param mContext/*from ww w. ja va 2 s .c om*/ * @param uri * @return */ public static String getMimeType(Context mContext, Uri uri) { ContentResolver cR = mContext.getContentResolver(); String mimeType = cR.getType(uri); if (mimeType == null) { mimeType = getMimeType(uri.toString()); } return mimeType; }
From source file:net.openid.appauth.JsonUtil.java
public static void putIfNotNull(@NonNull JSONObject json, @NonNull String field, @Nullable Uri value) { checkNotNull(json, "json must not be null"); checkNotNull(field, "field must not be null"); if (value == null) { return;//from w w w. jav a 2 s . c o m } try { json.put(field, value.toString()); } catch (JSONException ex) { throw new IllegalStateException("JSONException thrown in violation of contract", ex); } }
From source file:com.example.android.ennis.barrett.popularmovies.asynchronous.TMDbSyncUtil.java
private static String fetch(Uri uri) { HttpURLConnection connection = null; BufferedReader reader = null; String rawJSON = ""; Log.d(TAG, uri.toString()); try {//from w w w . ja v a 2 s .c om URL url = new URL(uri.toString()); //java.net Malformed uri exception connection = (HttpURLConnection) url.openConnection(); //java.io. IO exception connection.setRequestMethod("GET"); //java.net.ProtocolException && unnecessary connection.connect(); //java.io.IOExecption InputStream inputStream = connection.getInputStream(); // java.io.IOException StringBuffer stringBuffer = new StringBuffer(); if (inputStream == null) { return rawJSON; } reader = new BufferedReader(new InputStreamReader(inputStream)); //Make the string more readable String line; while ((line = reader.readLine()) != null) { stringBuffer.append(line + "\n"); } rawJSON = stringBuffer.toString(); Log.d(TAG + "doInBackground", rawJSON); } catch (IOException e) { Log.e(TAG, "Error ", e); e.printStackTrace(); } finally { if (connection != null) { connection.disconnect(); } if (reader != null) { try { reader.close(); } catch (final IOException e) { Log.e(TAG, "Error closing stream", e); } } } return rawJSON; }
From source file:Main.java
@Nullable public static File getFromMediaUri(Context context, ContentResolver resolver, Uri uri) { if (uri == null) return null; if (SCHEME_FILE.equals(uri.getScheme())) { return new File(uri.getPath()); } else if (SCHEME_CONTENT.equals(uri.getScheme())) { final String[] filePathColumn = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DISPLAY_NAME }; Cursor cursor = null;/*from w w w .j a v a 2 s.com*/ try { cursor = resolver.query(uri, filePathColumn, null, null, null); if (cursor != null && cursor.moveToFirst()) { final int columnIndex = (uri.toString().startsWith("content://com.google.android.gallery3d")) ? cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME) : cursor.getColumnIndex(MediaStore.MediaColumns.DATA); // Picasa images on API 13+ if (columnIndex != -1) { String filePath = cursor.getString(columnIndex); if (!TextUtils.isEmpty(filePath)) { return new File(filePath); } } } } catch (IllegalArgumentException e) { // Google Drive images return getFromMediaUriPfd(context, resolver, uri); } catch (SecurityException ignored) { // Nothing we can do } finally { if (cursor != null) cursor.close(); } } return null; }
From source file:com.hivewallet.androidclient.wallet.AddressBookProvider.java
/** Mark photo asset as permanent to prevent it from being removed during a clean up cycle. */ public static void setPhotoAssetAsPermanent(final Context context, @Nullable final Uri photoUri) { if (photoUri == null) return;//from www. ja v a 2s .co m final Uri uri = contentUri(context.getPackageName()); context.getContentResolver().call(uri, METHOD_SET_PHOTO_ASSET_AS_PERMANENT, photoUri.toString(), null); }
From source file:com.karura.framework.plugins.Capture.java
/** * Queries the media store to find out what the file path is for the Uri we supply * //from w w w. j ava 2 s. c om * @param contentUri * the Uri of the audio/image/video * @param context * the current application context * @return the full path to the file */ @SuppressWarnings("deprecation") public static String getRealPathFromURI(Uri contentUri, Activity context) { final String scheme = contentUri.getScheme(); if (scheme == null) { return contentUri.toString(); } else if (scheme.compareTo("content") == 0) { String[] proj = { DATA }; Cursor cursor = context.managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(DATA); cursor.moveToFirst(); return cursor.getString(column_index); } else if (scheme.compareTo("file") == 0) { return contentUri.getPath(); } else { return contentUri.toString(); } }
From source file:com.rightscale.provider.Dashboard.java
static public void performAction(Context context, Uri uri, String accountId, String action, String param) throws DashboardError { String mimeType = _getType(uri); if (!mimeType.startsWith("vnd.android.cursor.item/")) { throw new DashboardError("Cannot perform actions on collection resource " + uri.toString()); }//from w ww.ja v a2 s . c om List<String> pathSegments = uri.getPathSegments(); String id = pathSegments.get(pathSegments.size() - 1); try { DashboardSession session = createSession(context); session.login(); if (mimeType.endsWith(ServersResource.MIME_TYPE)) { ServersResource servers = new ServersResource(session, accountId); if (ACTION_LAUNCH.equals(action)) { servers.launch(id); } else if (ACTION_TERMINATE.equals(action)) { servers.terminate(id); } else if (ACTION_REBOOT.equals(action)) { servers.reboot(id); } else if (ACTION_RUN_SCRIPT.equals(action)) { servers.runScript(id, (String) param); } } else { throw new DashboardError("Cannot perform actions on unknown URI " + uri.toString()); } } catch (RestException e) { forgetSession(); Error err = new DashboardError(e); throw err; } }
From source file:com.hivewallet.androidclient.wallet.AddressBookProvider.java
/** Records a photo uri in the photo assets table. Returns {@code true} if the uri was already present. */ public static boolean insertOrUpdatePhotoUri(final Context context, @Nullable final Uri photoUri) { if (photoUri == null) return false; final Uri uri = contentUri(context.getPackageName()); Bundle bundle = context.getContentResolver().call(uri, METHOD_INSERT_OR_UPDATE_PHOTO_URI, photoUri.toString(), null); return bundle.getBoolean(PHOTO_URI_PRESENT); }
From source file:fr.mixit.android.io.JSONHandler.java
/** * Returns those id's from a {@link android.net.Uri} that were not found in a given set. *//*from w w w .j av a 2s .c om*/ protected static HashSet<String> getLostIds(Set<String> ids, Uri uri, String[] projection, int idColumnIndex, ContentResolver resolver) { final HashSet<String> lostIds = Sets.newHashSet(); final Cursor cursor = resolver.query(uri, projection, null, null, null); try { while (cursor.moveToNext()) { final String id = cursor.getString(idColumnIndex); if (!ids.contains(id)) { lostIds.add(id); } } } finally { cursor.close(); } if (!lostIds.isEmpty()) { Log.d(TAG, "Found " + lostIds.size() + " for " + uri.toString() + " that need to be removed."); } return lostIds; }