List of usage examples for android.net Uri getScheme
@Nullable public abstract String getScheme();
From source file:com.callrecorder.android.FileHelper.java
public static DocumentFile getStorageFile(Context context) { Uri uri = UserPreferences.getStorageUri(); String scheme = uri.getScheme(); if (scheme == null || scheme.equals("file")) { return DocumentFile.fromFile(new File(uri.getPath())); } else {/*from www . ja v a2s .co m*/ return DocumentFile.fromTreeUri(context, uri); } }
From source file:Main.java
public static String encodeQuery(String url) { Uri uri = Uri.parse(url); try {//from w w w . ja v a 2 s . c o m String query = uri.getQuery(); String encodedQuery = query != null ? URLEncoder.encode(query, "UTF-8") : null; URI tmp = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, uri.getFragment()); return tmp + (encodedQuery != null && encodedQuery.length() > 0 ? "?" + encodedQuery : ""); } catch (UnsupportedEncodingException ignore) { } catch (URISyntaxException ignore) { } return uri.toString(); }
From source file:Main.java
/** * /* w ww . j a v a 2 s. c om*/ * @param context * @param uri * uri of SCHEME_FILE or SCHEME_CONTENT * @return image path; uri will be changed to SCHEME_FILE */ public static String uriToImagePath(Context context, Uri uri) { if (context == null || uri == null) { return null; } String imagePath = null; String uriString = uri.toString(); String uriSchema = uri.getScheme(); if (uriSchema.equals(ContentResolver.SCHEME_FILE)) { imagePath = uriString.substring("file://".length()); } else {// uriSchema.equals(ContentResolver.SCHEME_CONTENT) ContentResolver resolver = context.getContentResolver(); Cursor cursor = resolver.query(uri, null, null, null, null); if (cursor.getCount() == 0) { Log.e(TAG, "Uri(" + uri.toString() + ") not found!"); return null; } cursor.moveToFirst(); imagePath = cursor.getString(1); // Change the SCHEME_CONTENT uri to the SCHEME_FILE. uri = Uri.fromFile(new File(imagePath)); } Log.v(TAG, "Final uri: " + uri.toString()); return imagePath; }
From source file:Main.java
private static boolean isMediaUri(Uri uri) { return uri != null && ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) && MediaStore.AUTHORITY.equals(uri.getAuthority()); }
From source file:Main.java
public static String getRealFilePath(final Context context, final Uri uri) { if (null == uri) return null; final String scheme = uri.getScheme(); String data = null;//from ww w. j av a 2s. co m if (scheme == null) data = uri.getPath(); else if (ContentResolver.SCHEME_FILE.equals(scheme)) { data = uri.getPath(); } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { Cursor cursor = context.getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); if (index > -1) { data = cursor.getString(index); } } cursor.close(); } } return data; }
From source file:Main.java
static String convertUriToPath(Context context, Uri uri) { Log.v(TAG, "convertUriToPath : " + uri + " @" + context); String path = null;// w w w .j a v a 2s. c o m if (null != uri) { String scheme = uri.getScheme(); if (null == scheme || scheme.equals("") || scheme.equals(ContentResolver.SCHEME_FILE)) { path = uri.getPath(); } else if (scheme.equals("http")) { path = uri.toString(); } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) { String[] projection = new String[] { MediaStore.MediaColumns.DATA }; Cursor cursor = null; try { cursor = context.getContentResolver().query(uri, projection, null, null, null); if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) { throw new IllegalArgumentException("Given Uri could not be found in media store"); } int pathIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); path = cursor.getString(pathIndex); } catch (SQLiteException e) { throw new IllegalArgumentException( "Given Uri is not formatted in a way so that it can be found in media store."); } finally { if (null != cursor) { cursor.close(); } } } else { throw new IllegalArgumentException("Given Uri scheme is not supported"); } } Log.v(TAG, "convertUriToPath : >" + path); return path; }
From source file:dev.nick.app.screencast.camera.MediaScratchFileProvider.java
public static boolean isMediaScratchSpaceUri(final Uri uri) { if (uri == null) { return false; }//from w ww . j a v a 2 s. c o m final List<String> segments = uri.getPathSegments(); return (TextUtils.equals(uri.getScheme(), ContentResolver.SCHEME_CONTENT) && TextUtils.equals(uri.getAuthority(), AUTHORITY) && segments.size() == 1 && isValidFileId(segments.get(0))); }
From source file:com.android.messaging.datamodel.MediaScratchFileProvider.java
public static boolean isMediaScratchSpaceUri(final Uri uri) { if (uri == null) { return false; }/*from w ww. j a v a 2 s . c o m*/ final List<String> segments = uri.getPathSegments(); return (TextUtils.equals(uri.getScheme(), ContentResolver.SCHEME_CONTENT) && TextUtils.equals(uri.getAuthority(), AUTHORITY) && segments.size() == 1 && FileProvider.isValidFileId(segments.get(0))); }
From source file:com.nttec.everychan.chans.WakabaFactory.java
private static ChanModule createChanModule(SharedPreferences preferences, Resources resources, String url, final DateFormat df) { Uri uri = Uri.parse(url); final String name = uri.getHost(); final boolean https = uri.getScheme() != null && uri.getScheme().equalsIgnoreCase("https"); return new AbstractWakabaModule(preferences, resources) { private final List<DateFormat> dateFormats; {//from w ww .j ava2 s .c om dateFormats = Arrays .asList(new DateFormat[] { df, new SimpleDateFormat("yy/MM/dd(EEE)HH:mm", Locale.US), new SimpleDateFormat("EEE dd MMM yyyy HH:mm:ss", Locale.US), new SimpleDateFormat("dd.MM.yyyy HH:mm:ss", Locale.US) { private static final long serialVersionUID = 1L; public Date parse(String string) throws ParseException { return super.parse(string.replaceAll(" ?\\(.*?\\)", "")); } }, new SimpleDateFormat("EEE yy/MM/dd HH:mm", Locale.US), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US) }); } @Override public String getDisplayingName() { return name; } @Override public String getChanName() { return name; } @Override public Drawable getChanFavicon() { return ResourcesCompat.getDrawable(resources, R.drawable.favicon_cirno, null); } @Override protected String getUsingDomain() { return name; } @Override protected SimpleBoardModel[] getBoardsList() { return new SimpleBoardModel[0]; } @Override protected boolean canHttps() { return true; } protected boolean useHttpsDefaultValue() { return https; }; @Override protected boolean canCloudflare() { return true; } @SuppressWarnings("serial") @SuppressLint("SimpleDateFormat") @Override protected WakabaReader getWakabaReader(InputStream stream, UrlPageModel urlModel) { return new WakabaReader(stream, new SimpleDateFormat() { // universal date format @Override public Date parse(String string) throws ParseException { for (DateFormat df : dateFormats) { try { return df.parse(string); } catch (Exception e) { } } Logger.d(TAG, "couldn't parse: '" + string + "'"); return new Date(0); } }); } }; }
From source file:com.whiuk.philip.opensmime.PathConverter.java
public static FileInformation getFileInformation(final Context context, final Uri uri) { final String uriScheme = uri.getScheme(); if ("file".equals(uriScheme)) { return handleFileScheme(context, uri); }/*from www . j av a 2 s . c o m*/ if ("content".equals(uriScheme)) { return handleContentScheme(context, uri); } return null; }