1 /* ownCloud Android client application
2 * Copyright (C) 2012-2014 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package com
.owncloud
.android
.utils
;
20 import android
.content
.Context
;
21 import android
.database
.Cursor
;
22 import android
.net
.Uri
;
26 * A helper class for some Uri operations.
28 public class UriUtils
{
30 public static final String URI_CONTENT_SCHEME
= "content://";
34 * Get the value of the data column for this Uri. This is useful for
35 * MediaStore Uris, and other file-based ContentProviders.
37 * @param context The context.
38 * @param uri The Uri to query.
39 * @param selection (Optional) Filter used in the query.
40 * @param selectionArgs (Optional) Selection arguments used in the query.
41 * @return The value of the _data column, which is typically a file path.
43 public static String
getDataColumn(Context context
, Uri uri
, String selection
, String
[] selectionArgs
) {
46 final String column
= "_data";
47 final String
[] projection
= { column
};
50 cursor
= context
.getContentResolver().query(uri
, projection
, selection
, selectionArgs
, null
);
51 if (cursor
!= null
&& cursor
.moveToFirst()) {
53 final int column_index
= cursor
.getColumnIndexOrThrow(column
);
54 return cursor
.getString(column_index
);
64 * @param uri The Uri to check.
65 * @return Whether the Uri authority is ExternalStorageProvider.
67 public static boolean isExternalStorageDocument(Uri uri
) {
68 return "com.android.externalstorage.documents".equals(uri
.getAuthority());
72 * @param uri The Uri to check.
73 * @return Whether the Uri authority is DownloadsProvider.
75 public static boolean isDownloadsDocument(Uri uri
) {
76 return "com.android.providers.downloads.documents".equals(uri
.getAuthority());
80 * @param uri The Uri to check.
81 * @return Whether the Uri authority is MediaProvider.
83 public static boolean isMediaDocument(Uri uri
) {
84 return "com.android.providers.media.documents".equals(uri
.getAuthority());
88 * @param uri The Uri to check.
89 * @return Whether the Uri authority is Google Photos.
91 public static boolean isGooglePhotosUri(Uri uri
) {
92 return "com.google.android.apps.photos.content".equals(uri
.getAuthority());
97 * @param uri The Uri to check.
98 * @return Whether the Uri is from a content provider as kind "content://..."
100 public static boolean isContentDocument(Uri uri
) {
101 return uri
.toString().startsWith(URI_CONTENT_SCHEME
);