2 * ownCloud Android client application
4 * Copyright (C) 2015 ownCloud Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.utils
;
22 import android
.content
.Context
;
23 import android
.database
.Cursor
;
24 import android
.net
.Uri
;
28 * A helper class for some Uri operations.
30 public class UriUtils
{
32 public static final String URI_CONTENT_SCHEME
= "content://";
36 * Get the value of the data column for this Uri. This is useful for
37 * MediaStore Uris, and other file-based ContentProviders.
39 * @param context The context.
40 * @param uri The Uri to query.
41 * @param selection (Optional) Filter used in the query.
42 * @param selectionArgs (Optional) Selection arguments used in the query.
43 * @return The value of the _data column, which is typically a file path.
45 public static String
getDataColumn(Context context
, Uri uri
, String selection
, String
[] selectionArgs
) {
48 final String column
= "_data";
49 final String
[] projection
= { column
};
52 cursor
= context
.getContentResolver().query(uri
, projection
, selection
, selectionArgs
, null
);
53 if (cursor
!= null
&& cursor
.moveToFirst()) {
55 final int column_index
= cursor
.getColumnIndexOrThrow(column
);
56 return cursor
.getString(column_index
);
66 * @param uri The Uri to check.
67 * @return Whether the Uri authority is ExternalStorageProvider.
69 public static boolean isExternalStorageDocument(Uri uri
) {
70 return "com.android.externalstorage.documents".equals(uri
.getAuthority());
74 * @param uri The Uri to check.
75 * @return Whether the Uri authority is DownloadsProvider.
77 public static boolean isDownloadsDocument(Uri uri
) {
78 return "com.android.providers.downloads.documents".equals(uri
.getAuthority());
82 * @param uri The Uri to check.
83 * @return Whether the Uri authority is MediaProvider.
85 public static boolean isMediaDocument(Uri uri
) {
86 return "com.android.providers.media.documents".equals(uri
.getAuthority());
90 * @param uri The Uri to check.
91 * @return Whether the Uri authority is Google Photos.
93 public static boolean isGooglePhotosUri(Uri uri
) {
94 return "com.google.android.apps.photos.content".equals(uri
.getAuthority());
99 * @param uri The Uri to check.
100 * @return Whether the Uri is from a content provider as kind "content://..."
102 public static boolean isContentDocument(Uri uri
) {
103 return uri
.toString().startsWith(URI_CONTENT_SCHEME
);