List of usage examples for android.net Uri getPath
@Nullable public abstract String getPath();
From source file:Main.java
/** * Convert Uri into File./*w ww . ja va 2 s .c om*/ * @param uri * @return file */ public static File getFile(Uri uri) { if (uri != null) { String filepath = uri.getPath(); if (filepath != null) { return new File(filepath); } } return null; }
From source file:com.linkedin.android.shaky.Utils.java
/** * Get the file provider Uri, so that internal files can be temporarily shared with other apps. * * Requires AndroidManifest permission: android.support.v4.content.FileProvider *///from w ww. j a v a 2 s . c o m @NonNull static Uri getProviderUri(@NonNull Context context, @NonNull Uri uri) { File file = new File(uri.getPath()); return getProviderUri(context, file); }
From source file:edu.stanford.mobisocial.dungbeetle.model.Feed.java
public static FeedType typeOf(Uri feedUri) { String path = feedUri.getPath(); if (path.startsWith("/feeds/friends^") || path.startsWith("/members/friends^")) { return FeedType.FRIEND; } else if (path.startsWith("/feeds/app^") || path.startsWith("/members/app^")) { return FeedType.APP; } else if (path.startsWith("/feeds/related/")) { return FeedType.RELATED; }/*from w w w . j av a 2s.c o m*/ return FeedType.GROUP; }
From source file:Main.java
/** * Get path of image from uri//from w ww . j a v a 2s. c o m * * @param contentResolver * @param contentURI * @return path of image. Null if not found. */ public static String getRealImagePathFromURI(ContentResolver contentResolver, Uri contentURI) { Cursor cursor = contentResolver.query(contentURI, null, null, null, null); if (cursor == null) return contentURI.getPath(); else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(Images.ImageColumns.DATA); try { return cursor.getString(idx); } catch (Exception exception) { return null; } } }
From source file:Main.java
/** * Get path of video from uri/*from w ww.j av a 2 s.c o m*/ * * @param contentResolver * @param contentURI * @return path of video. Null if not found. */ public static String getRealVideoPathFromURI(ContentResolver contentResolver, Uri contentURI) { Cursor cursor = contentResolver.query(contentURI, null, null, null, null); if (cursor == null) return contentURI.getPath(); else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(Video.VideoColumns.DATA); try { return cursor.getString(idx); } catch (Exception exception) { return null; } } }
From source file:Main.java
/** * This method to get real path from uri. * //ww w. jav a 2s .c o m * @param context * @param contentURI * @return imagepath */ public static String getRealPathFromURI(Context context, Uri contentURI) { Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); if (cursor == null) { return contentURI.getPath(); } else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); return cursor.getString(idx); } }
From source file:Main.java
public static File getFromMediaUri(ContentResolver resolver, Uri uri) { if (uri == null) return null; if ("file".equals(uri.getScheme())) { return new File(uri.getPath()); } else if ("content".equals(uri.getScheme())) { final String[] filePathColumn = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DISPLAY_NAME }; Cursor cursor = null;// ww w.j a v a 2 s . c o m 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); if (columnIndex != -1) { String filePath = cursor.getString(columnIndex); if (!TextUtils.isEmpty(filePath)) { return new File(filePath); } } } } catch (SecurityException ignored) { } finally { if (cursor != null) cursor.close(); } } return null; }
From source file:com.madgag.agit.DashboardActivity.java
public static File getFile(Uri uri) { if (uri != null) { String filepath = uri.getPath(); if (filepath != null) { return new File(filepath); }/*from w w w .ja va 2s . c o m*/ } return null; }
From source file:Main.java
public static String makeSpecUrl(String inBaseUrl) { Uri path = Uri.parse(inBaseUrl); String port = path.getPort() != -1 ? ":" + String.valueOf(path.getPort()) : ""; return path.getScheme() + "://" + path.getHost() + port + path.getPath(); }
From source file:Main.java
/** * Converts the uri to an InputStream./* w ww .j a v a2 s . c om*/ * * @param context Context used to resolve file and content. * @param uri Uri to convert. * @return InputStream or null if something went wrong. */ private static InputStream toInputStream(Context context, Uri uri) { String scheme = uri.getScheme(); if (scheme.equals("http") || scheme.equals("https")) { try { return new URL(uri.getPath()).openConnection().getInputStream(); } catch (NullPointerException e) { return null; } catch (MalformedURLException e) { return null; } catch (IOException e) { return null; } } else if (scheme.equals("file") || scheme.equals("content")) { try { return context.getContentResolver().openInputStream(uri); } catch (FileNotFoundException e) { return null; } } return null; }